From e959b77ff70b3eb2030c7b902e88206e03d6a81b Mon Sep 17 00:00:00 2001 From: Loris Sauter Date: Wed, 10 Jan 2024 14:25:27 +0100 Subject: [PATCH] #454: Added simple copy button in task template list --- .../task-templates-list.component.html | 3 +++ .../task-templates-list.component.scss | 2 +- .../tasks-list/task-templates-list.component.ts | 17 +++++++++++++++++ .../template-builder.service.ts | 8 ++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.html b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.html index 8d1eb763..b9db3339 100644 --- a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.html +++ b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.html @@ -47,6 +47,9 @@

Tasks

+ diff --git a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.scss b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.scss index 5fe8475e..a1e8948c 100644 --- a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.scss +++ b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.scss @@ -7,7 +7,7 @@ } .mat-column-actions{ - width: 20%; + width: 25%; } .mat-mdc-row:hover { diff --git a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.ts b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.ts index d548b8b4..11a004a6 100644 --- a/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.ts +++ b/frontend/src/app/template/template-builder/components/tasks-list/task-templates-list.component.ts @@ -103,6 +103,23 @@ export class TaskTemplatesListComponent extends AbstractTemplateBuilderComponent this.selection.toggle(task); } + public copyTask(task: ApiTaskTemplate){ + const copy = JSON.parse(JSON.stringify(task)) + copy.id = undefined; + const temp = { + name: "", + description: "---Automatically generated template whose elements get copied. If this is seen, there was a programmer's error somewhere---", + taskTypes: [], + taskGroups: [], + tasks: [copy], + teams: [], + teamGroups: [], + judges: [], + id: "---COPY_TEMPLATE_NO_ID---" + } as ApiEvaluationTemplate; + this.builderService.importFrom(temp, "(Copy)") + } + public tasksLength() { return this.builderService.getTemplate().tasks.length; } diff --git a/frontend/src/app/template/template-builder/template-builder.service.ts b/frontend/src/app/template/template-builder/template-builder.service.ts index 51773e05..1cdd03db 100644 --- a/frontend/src/app/template/template-builder/template-builder.service.ts +++ b/frontend/src/app/template/template-builder/template-builder.service.ts @@ -262,7 +262,7 @@ export class TemplateBuilderService { return result; } - importFrom(from: ApiEvaluationTemplate) { + importFrom(from: ApiEvaluationTemplate, nameCollisionSuffix = "(Imported)") { /* Import check is currently on name, may switch to completely UUID based matching */ const alteredTypes: Map = new Map() @@ -274,7 +274,7 @@ export class TemplateBuilderService { this.getTemplate().taskTypes.push(it) }else{ const legacyName = it.name - it.name = `${it.name} (Imported)` + it.name = `${it.name} ${nameCollisionSuffix}` alteredTypes.set(legacyName, it) this.getTemplate().taskTypes.push(it) } @@ -288,7 +288,7 @@ export class TemplateBuilderService { this.getTemplate().taskGroups.push(it) }else{ const legacyName = it.name - it.name = `${it.name} (Imported)` + it.name = `${it.name} ${nameCollisionSuffix}` alteredGroups.set(legacyName, it) this.getTemplate().taskGroups.push(it) } @@ -304,7 +304,7 @@ export class TemplateBuilderService { if(!this.getTemplate().tasks.map(that => that.name).includes(it.name)){ this.getTemplate().tasks.push(it) }else{ - it.name = `${it.name} (Imported)` + it.name = `${it.name} ${nameCollisionSuffix}` this.getTemplate().tasks.push(it) } })