@@ -606,10 +606,7 @@ export default {
606
606
607
607
async afterLoadData () {
608
608
if (this .sourceItemId ) {
609
- const item = (await axios ({
610
- url: ` /api/project/${ this .projectId } /templates/${ this .sourceItemId } ` ,
611
- responseType: ' json' ,
612
- })).data ;
609
+ const item = await this .loadProjectResource (' templates' , this .sourceItemId );
613
610
614
611
item .id = null ;
615
612
@@ -619,10 +616,7 @@ export default {
619
616
}
620
617
}
621
618
622
- const sourceSchedule = (await axios ({
623
- url: ` /api/project/${ this .projectId } /templates/${ this .sourceItemId } /schedules` ,
624
- responseType: ' json' ,
625
- })).data [0 ];
619
+ const sourceSchedule = (await this .loadProjectEndpoint (` /templates/${ this .sourceItemId } /schedules` ))[0 ];
626
620
627
621
if (sourceSchedule != null ) {
628
622
this .cronFormat = sourceSchedule .cron_format ;
@@ -637,36 +631,33 @@ export default {
637
631
this .item .task_params = {};
638
632
}
639
633
640
- this .repositories = (await axios ({
641
- url: ` /api/project/${ this .projectId } /repositories` ,
642
- responseType: ' json' ,
643
- })).data ;
644
-
645
- this .inventory = [
646
- ... (await axios ({
647
- url: ` /api/project/${ this .projectId } /inventory?app=${ this .app } &template_id=${ this .itemId } ` ,
648
- responseType: ' json' ,
649
- })).data ,
650
-
651
- ... (await axios ({
652
- url: ` /api/project/${ this .projectId } /inventory?app=${ this .app } ` ,
653
- responseType: ' json' ,
654
- })).data ,
655
- ];
656
-
657
- this .environment = (await axios ({
658
- url: ` /api/project/${ this .projectId } /environment` ,
659
- responseType: ' json' ,
660
- })).data ;
661
-
662
- const template = (await axios ({
663
- url: ` /api/project/${ this .projectId } /templates` ,
664
- responseType: ' json' ,
665
- })).data ;
634
+ let templates;
635
+ let inventory1;
636
+ let inventory2;
637
+
638
+ [
639
+ this .repositories ,
640
+ inventory1,
641
+ inventory2,
642
+ this .schedules ,
643
+ this .views ,
644
+ this .environment ,
645
+ templates,
646
+ ] = await Promise .all ([
647
+ this .loadProjectResources (' repositories' ),
648
+ this .loadProjectEndpoint (` /inventory?app=${ this .app } &template_id=${ this .itemId } ` ),
649
+ this .loadProjectEndpoint (` /inventory?app=${ this .app } ` ),
650
+ this .isNew ? [] : this .loadProjectEndpoint (` /templates/${ this .itemId } /schedules` ),
651
+ this .loadProjectResources (' views' ),
652
+ this .loadProjectResources (' environment' ),
653
+ this .loadProjectResources (' templates' ),
654
+ ]);
655
+
656
+ this .inventory = [... inventory1, ... inventory2];
666
657
667
658
const builds = [];
668
659
const deploys = [];
669
- template .forEach ((t ) => {
660
+ templates .forEach ((t ) => {
670
661
switch (t .type ) {
671
662
case ' build' :
672
663
if (builds .length === 0 ) {
@@ -693,16 +684,6 @@ export default {
693
684
}
694
685
this .buildTemplates .push (... deploys);
695
686
696
- this .schedules = this .isNew ? [] : (await axios ({
697
- url: ` /api/project/${ this .projectId } /templates/${ this .itemId } /schedules` ,
698
- responseType: ' json' ,
699
- })).data ;
700
-
701
- this .views = (await axios ({
702
- url: ` /api/project/${ this .projectId } /views` ,
703
- responseType: ' json' ,
704
- })).data ;
705
-
706
687
if (this .schedules .length > 0 ) {
707
688
const schedule = this .schedules .find ((s ) => s .repository_id != null );
708
689
if (schedule != null ) {
0 commit comments