Skip to content

Commit

Permalink
Create tag interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JeltevanBoheemen committed Nov 8, 2023
1 parent 7055265 commit c31d3bb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class ApiService {

public createTag(name: string, description?: string): Observable<Tag> {
const url = this.apiRoute(this.tagApiUrl, 'tags/');
return this.http.put<Tag>(url, { name, description });
return this.http.post<Tag>(url, { name, description });
}

public documentTags(document: FoundDocument): Observable<DocumentTagsResponse> {
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/app/tag/tag-select/tag-select.component.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
<div class="field has-addons">
<div class="control">
<ng-container *ngIf="!createMode">
<div class="control" *ngIf="!createMode">
<ng-container *ngIf="filterTags(tags$ | async, exclude) as filteredTags">
<p-dropdown [options]="filteredTags" [(ngModel)]="selectedTag" optionLabel="name" emptyMessage="niks hier"
[disabled]="!filteredTags.length"
[placeholder]="filteredTags.length ? 'Assign a tag' : 'No more tags to assign'" styleClass="is-small">
<ng-template pTemplate="footer">
<button class="button tag" aria-label="add tag" (click)="toggleCreate()">
<span class="icon"><fa-icon [icon]="faPlus"></fa-icon></span>
<span>Create a new tag</span>
</button>
</ng-template>
</p-dropdown>
</ng-container>
</div>
<div class="control">
<button class="button tag" aria-label="add tag" (click)="confirm()" [disabled]="!selectedTag">
<button class="button tag" aria-label="add tag" (click)="addTag()" [disabled]="!selectedTag">
<span class="icon"><fa-icon [icon]="faCheck"></fa-icon></span>
</button>
</div>
</ng-container>
<ng-container *ngIf="createMode">
<div class="control">
<input type="text" class="input tag" placeholder="Enter tag name" [(ngModel)]="newTagName">
</div>
<div class="control">
<button class="button tag" aria-label="create tag" (click)="createTag()" [disabled]="!newTagName">
<span class="icon"><fa-icon [icon]="faCheck"></fa-icon></span>
</button>
</div>
</ng-container>

<div class="control">
<button class="button tag" aria-label="cancel" type="reset" (click)="cancel.emit()">
<span class="icon"><fa-icon [icon]="faTimes"></fa-icon></span>
Expand Down
49 changes: 41 additions & 8 deletions frontend/src/app/tag/tag-select/tag-select.component.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { TagService } from '../../services/tag.service';
import { Observable } from 'rxjs';
import { Tag } from '../../models';
import { faCheck, faTimes } from '@fortawesome/free-solid-svg-icons';
import {
Component,
ElementRef,
EventEmitter,
Input,
OnDestroy,
Output,
ViewChild,
} from '@angular/core';
import { faCheck, faPlus, faTimes } from '@fortawesome/free-solid-svg-icons';
import * as _ from 'lodash';

import { Observable, Subject } from 'rxjs';
import { Tag } from '../../models';
import { TagService } from '../../services/tag.service';
import { takeUntil } from 'rxjs/operators';

@Component({
selector: 'ia-tag-select',
templateUrl: './tag-select.component.html',
styleUrls: ['./tag-select.component.scss'],
})
export class TagSelectComponent {
export class TagSelectComponent implements OnDestroy {
@Input() exclude: Tag[];
@Output() selection = new EventEmitter<Tag>();
@Output() cancel = new EventEmitter<void>();

@ViewChild('tagSelect') tagSelect: ElementRef;

tags$: Observable<Tag[]>;
destroy$ = new Subject();

faCheck = faCheck;
faTimes = faTimes;
faPlus = faPlus;

selectedTag: Tag;

createMode = false;
newTagName: string;

constructor(private tagService: TagService) {
this.tags$ = this.tagService.tags$;
}
Expand All @@ -33,8 +46,28 @@ export class TagSelectComponent {
return _.differenceBy(tags, exclude || [], 'name');
}

confirm() {
addTag() {
this.selection.emit(this.selectedTag);
this.selectedTag = undefined;
}

createTag() {
this.tagService
.makeTag(this.newTagName)
.pipe(takeUntil(this.destroy$))
.subscribe((res) => {
this.selection.emit(res);
this.createMode = false;
});
}

toggleCreate(): void {
this.selectedTag = undefined;
this.createMode = !this.createMode;
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}

0 comments on commit c31d3bb

Please sign in to comment.