|
|
@ -1,9 +1,10 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
|
|
|
|
AfterViewInit,
|
|
|
|
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
Component,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Input,
|
|
|
|
OnChanges,
|
|
|
|
OnChanges,
|
|
|
|
OnInit,
|
|
|
|
|
|
|
|
Output,
|
|
|
|
Output,
|
|
|
|
SimpleChanges,
|
|
|
|
SimpleChanges,
|
|
|
|
ViewChild
|
|
|
|
ViewChild
|
|
|
@ -12,31 +13,35 @@ import {File} from "../../../../../api/models/File";
|
|
|
|
import {Tag} from "../../../../../api/models/Tag";
|
|
|
|
import {Tag} from "../../../../../api/models/Tag";
|
|
|
|
import {CdkVirtualScrollViewport} from "@angular/cdk/scrolling";
|
|
|
|
import {CdkVirtualScrollViewport} from "@angular/cdk/scrolling";
|
|
|
|
import {TagService} from "../../../../services/tag/tag.service";
|
|
|
|
import {TagService} from "../../../../services/tag/tag.service";
|
|
|
|
|
|
|
|
import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service";
|
|
|
|
|
|
|
|
import {BusyIndicatorComponent} from "../../app-common/busy-indicator/busy-indicator.component";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: "app-tag-edit",
|
|
|
|
selector: "app-tag-edit",
|
|
|
|
templateUrl: "./tag-edit.component.html",
|
|
|
|
templateUrl: "./tag-edit.component.html",
|
|
|
|
styleUrls: ["./tag-edit.component.scss"]
|
|
|
|
styleUrls: ["./tag-edit.component.scss"],
|
|
|
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
export class TagEditComponent implements AfterViewInit, OnChanges {
|
|
|
|
|
|
|
|
|
|
|
|
@Input() files: File[] = [];
|
|
|
|
@Input() files: File[] = [];
|
|
|
|
@Output() tagEditEvent = new EventEmitter<TagEditComponent>();
|
|
|
|
@Output() tagEditEvent = new EventEmitter<TagEditComponent>();
|
|
|
|
public tags: Tag[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild("tagScroll") tagScroll!: CdkVirtualScrollViewport;
|
|
|
|
|
|
|
|
@ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public tags: Tag[] = [];
|
|
|
|
public allTags: Tag[] = [];
|
|
|
|
public allTags: Tag[] = [];
|
|
|
|
public editMode: string = "Toggle";
|
|
|
|
public editMode: string = "Toggle";
|
|
|
|
@ViewChild("tagScroll") tagScroll!: CdkVirtualScrollViewport;
|
|
|
|
|
|
|
|
private fileTags: { [key: number]: Tag[] } = {};
|
|
|
|
private fileTags: { [key: number]: Tag[] } = {};
|
|
|
|
|
|
|
|
|
|
|
|
public loading = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
|
|
|
|
private errorBroker: ErrorBrokerService,
|
|
|
|
private tagService: TagService,
|
|
|
|
private tagService: TagService,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
async ngAfterViewInit() {
|
|
|
|
this.tagService.tags.subscribe(tags => this.allTags = tags);
|
|
|
|
this.tagService.tags.subscribe(tags => this.allTags = tags);
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
@ -50,7 +55,6 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async editTag(tag: string): Promise<void> {
|
|
|
|
public async editTag(tag: string): Promise<void> {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
if (tag.length > 0) {
|
|
|
|
if (tag.length > 0) {
|
|
|
|
let tagInstance = this.allTags.find(
|
|
|
|
let tagInstance = this.allTags.find(
|
|
|
|
t => t.getNormalizedOutput() === tag);
|
|
|
|
t => t.getNormalizedOutput() === tag);
|
|
|
@ -71,10 +75,10 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async toggleTag(tag: Tag) {
|
|
|
|
async toggleTag(tag: Tag) {
|
|
|
|
|
|
|
|
await this.wrapAsyncOperation(async () => {
|
|
|
|
for (const file of this.files) {
|
|
|
|
for (const file of this.files) {
|
|
|
|
const fileTags = this.fileTags[file.id];
|
|
|
|
const fileTags = this.fileTags[file.id];
|
|
|
|
let addedTags = [];
|
|
|
|
let addedTags = [];
|
|
|
@ -86,7 +90,8 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
file.id,
|
|
|
|
file.id,
|
|
|
|
addedTags, removedTags);
|
|
|
|
addedTags, removedTags
|
|
|
|
|
|
|
|
);
|
|
|
|
if (addedTags.length > 0) {
|
|
|
|
if (addedTags.length > 0) {
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
@ -97,15 +102,18 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
if (index >= 0) {
|
|
|
|
if (index >= 0) {
|
|
|
|
this.tagScroll.scrollToIndex(index);
|
|
|
|
this.tagScroll.scrollToIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async addTag(tag: Tag) {
|
|
|
|
async addTag(tag: Tag) {
|
|
|
|
|
|
|
|
await this.wrapAsyncOperation(async () => {
|
|
|
|
for (const file of this.files) {
|
|
|
|
for (const file of this.files) {
|
|
|
|
if ((this.fileTags[file.id] ?? []).findIndex(t => t.id === tag.id) < 0) {
|
|
|
|
if ((this.fileTags[file.id] ?? []).findIndex(t => t.id === tag.id) < 0) {
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
file.id,
|
|
|
|
file.id,
|
|
|
|
[tag.id], []);
|
|
|
|
[tag.id], []
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
@ -113,27 +121,29 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
if (index >= 0) {
|
|
|
|
if (index >= 0) {
|
|
|
|
this.tagScroll.scrollToIndex(index);
|
|
|
|
this.tagScroll.scrollToIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadTags();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
|
await this.tagService.loadNamespaces();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async removeTag(tag: Tag) {
|
|
|
|
public async removeTag(tag: Tag) {
|
|
|
|
this.loading = true;
|
|
|
|
await this.wrapAsyncOperation(async () => {
|
|
|
|
for (const file of this.files) {
|
|
|
|
for (const file of this.files) {
|
|
|
|
if (this.fileTags[file.id].findIndex(t => t.id === tag.id) >= 0) {
|
|
|
|
if (this.fileTags[file.id].findIndex(t => t.id === tag.id) >= 0) {
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
this.fileTags[file.id] = await this.tagService.changeFileTags(
|
|
|
|
file.id,
|
|
|
|
file.id,
|
|
|
|
[], [tag.id]);
|
|
|
|
[], [tag.id]
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
this.tagEditEvent.emit(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async loadFileTags() {
|
|
|
|
private async loadFileTags() {
|
|
|
|
this.loading = true;
|
|
|
|
await this.wrapAsyncOperation(async () => {
|
|
|
|
const promises = [];
|
|
|
|
const promises = [];
|
|
|
|
const loadFn = async (file: File) => {
|
|
|
|
const loadFn = async (file: File) => {
|
|
|
|
this.fileTags[file.id] = await this.tagService.getTagsForFiles(
|
|
|
|
this.fileTags[file.id] = await this.tagService.getTagsForFiles(
|
|
|
@ -145,7 +155,7 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
|
|
|
|
|
|
|
|
await Promise.all(promises);
|
|
|
|
await Promise.all(promises);
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
|
this.mapFileTagsToTagList();
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private mapFileTagsToTagList() {
|
|
|
|
private mapFileTagsToTagList() {
|
|
|
@ -160,4 +170,17 @@ export class TagEditComponent implements OnInit, OnChanges {
|
|
|
|
(a, b) => a.getNormalizedOutput()
|
|
|
|
(a, b) => a.getNormalizedOutput()
|
|
|
|
.localeCompare(b.getNormalizedOutput()));
|
|
|
|
.localeCompare(b.getNormalizedOutput()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async wrapAsyncOperation<T>(cb: () => Promise<T>): Promise<T | undefined> {
|
|
|
|
|
|
|
|
if (!this.busyIndicator) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return cb();
|
|
|
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
|
|
|
this.errorBroker.showError(err);
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return this.busyIndicator.wrapAsyncOperation(cb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|