Browse Source

Support project clone in frontend

pull/2204/head
Hironsan 1 year ago
parent
commit
a0240c2fa4
3 changed files with 27 additions and 0 deletions
  1. 13
      frontend/pages/projects/index.vue
  2. 6
      frontend/repositories/project/apiProjectRepository.ts
  3. 8
      frontend/services/application/project/projectApplicationService.ts

13
frontend/pages/projects/index.vue

@ -4,6 +4,9 @@
<v-btn class="text-capitalize" color="primary" @click.stop="$router.push('projects/create')">
{{ $t('generic.create') }}
</v-btn>
<v-btn class="text-capitalize ms-2" color="primary" :disabled="!canClone" @click.stop="clone">
Clone
</v-btn>
<v-btn
class="text-capitalize ms-2"
:disabled="!canDelete"
@ -66,6 +69,10 @@ export default Vue.extend({
...mapGetters('auth', ['isStaff']),
canDelete(): boolean {
return this.selected.length > 0
},
canClone(): boolean {
return this.selected.length === 1
}
},
@ -84,6 +91,12 @@ export default Vue.extend({
this.selected = []
},
async clone() {
const project = await this.$services.project.clone(this.selected[0])
this.selected = []
this.$router.push(`/projects/${project.id}/settings`)
},
updateQuery(query: object) {
this.$router.push(query)
}

6
frontend/repositories/project/apiProjectRepository.ts

@ -109,4 +109,10 @@ export class APIProjectRepository {
const url = `/projects`
await this.request.delete(url, { ids: projectIds })
}
async clone(project: Project): Promise<Project> {
const url = `/projects/${project.id}/clone`
const response = await this.request.post(url)
return toModel(response.data)
}
}

8
frontend/services/application/project/projectApplicationService.ts

@ -116,4 +116,12 @@ export class ProjectApplicationService {
const ids = projects.map((project) => project.id)
return this.repository.bulkDelete(ids)
}
public async clone(project: Project): Promise<Project> {
try {
return await this.repository.clone(project)
} catch (e: any) {
throw new Error(e.response.data.detail)
}
}
}
Loading…
Cancel
Save