Skip to content

Commit

Permalink
#454: Added simple copy button in task template list
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterl committed Jan 10, 2024
1 parent 59507f8 commit e959b77
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ <h2>Tasks</h2>
<button mat-icon-button aria-label="Edit task." matTooltip="Edit task." (click)="editTask(task)">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button aria-label="Remove task." matTooltip="Remove task." (click)="copyTask(task)">

This comment has been minimized.

Copy link
@lucaro

lucaro Jan 10, 2024

Collaborator

Should probably say 'Copy' rather than 'Remove' then...

<mat-icon>content_copy</mat-icon>
</button>
<button mat-icon-button aria-label="Remove task." matTooltip="Remove task." (click)="removeTask(task)">
<mat-icon>delete</mat-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.mat-column-actions{
width: 20%;
width: 25%;
}

.mat-mdc-row:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<COPY-TEMPLATE>",
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,ApiTaskType> = new Map<string, ApiTaskType>()
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
})
Expand Down

0 comments on commit e959b77

Please sign in to comment.