Skip to content

Commit b6a0c2b

Browse files
committed
refactor(ui): add mixin ProjectMixin with project related methods
1 parent 39ed4a1 commit b6a0c2b

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

web/src/components/ItemListPageBase.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ObjectRefsDialog from '@/components/ObjectRefsDialog.vue';
77
import { getErrorMessage } from '@/lib/error';
88
import { USER_PERMISSIONS } from '@/lib/constants';
99
import PermissionsCheck from '@/components/PermissionsCheck';
10+
import ProjectMixin from '@/components/ProjectMixin';
1011

1112
export default {
1213
components: {
@@ -15,10 +16,9 @@ export default {
1516
ObjectRefsDialog,
1617
},
1718

18-
mixins: [PermissionsCheck],
19+
mixins: [PermissionsCheck, ProjectMixin],
1920

2021
props: {
21-
projectId: Number,
2222
projectType: String,
2323
userId: Number,
2424
userRole: String,
@@ -141,13 +141,5 @@ export default {
141141
responseType: 'json',
142142
})).data;
143143
},
144-
145-
async loadProjectResources(name) {
146-
return (await axios({
147-
method: 'get',
148-
url: `/api/project/${this.projectId}/${name}`,
149-
responseType: 'json',
150-
})).data;
151-
},
152144
},
153145
};

web/src/components/ProjectMixin.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from 'axios';
2+
3+
export default {
4+
props: {
5+
projectId: Number,
6+
},
7+
8+
methods: {
9+
async loadProjectResources(name) {
10+
return (await axios({
11+
method: 'get',
12+
url: `/api/project/${this.projectId}/${name}`,
13+
responseType: 'json',
14+
})).data;
15+
},
16+
async loadProjectResource(name, id) {
17+
return (await axios({
18+
method: 'get',
19+
url: `/api/project/${this.projectId}/${name}/${id}`,
20+
responseType: 'json',
21+
})).data;
22+
},
23+
},
24+
};

web/src/lib/api.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import axios from 'axios';
2+
3+
export async function loadProjectResources(name) {
4+
return (await axios({
5+
method: 'get',
6+
url: `/api/project/${this.projectId}/${name}`,
7+
responseType: 'json',
8+
})).data;
9+
}
10+
11+
export async function test() {
12+
return null;
13+
}

web/src/views/project/TemplateView.vue

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ import NewTaskDialog from '@/components/NewTaskDialog.vue';
160160
import EditTemplateDialog from '@/components/EditTemplateDialog.vue';
161161
import PermissionsCheck from '@/components/PermissionsCheck';
162162
import SingleLineEditable from '@/components/SingleLineEditable.vue';
163+
import ProjectMixin from '@/components/ProjectMixin';
163164
164165
export default {
165166
components: {
@@ -176,7 +177,7 @@ export default {
176177
premiumFeatures: Object,
177178
},
178179
179-
mixins: [PermissionsCheck],
180+
mixins: [PermissionsCheck, ProjectMixin],
180181
181182
data() {
182183
return {
@@ -294,37 +295,17 @@ export default {
294295
},
295296
296297
async loadData() {
297-
this.item = (
298-
await axios({
299-
method: 'get',
300-
url: `/api/project/${this.projectId}/templates/${this.itemId}`,
301-
responseType: 'json',
302-
})
303-
).data;
304-
305-
this.inventory = (
306-
await axios({
307-
method: 'get',
308-
url: `/api/project/${this.projectId}/inventory`,
309-
responseType: 'json',
310-
})
311-
).data;
312-
313-
this.environment = (
314-
await axios({
315-
method: 'get',
316-
url: `/api/project/${this.projectId}/environment`,
317-
responseType: 'json',
318-
})
319-
).data;
320-
321-
this.repositories = (
322-
await axios({
323-
method: 'get',
324-
url: `/api/project/${this.projectId}/repositories`,
325-
responseType: 'json',
326-
})
327-
).data;
298+
[
299+
this.item,
300+
this.inventory,
301+
this.environment,
302+
this.repositories,
303+
] = await Promise.all([
304+
this.loadProjectResource('templates', this.itemId),
305+
this.loadProjectResources('inventory'),
306+
this.loadProjectResources('environment'),
307+
this.loadProjectResources('repositories'),
308+
]);
328309
},
329310
330311
async updateDescription() {

0 commit comments

Comments
 (0)