@ -6,7 +6,7 @@ import {
OnInit ,
SimpleChanges ,
ViewChild
} from '@angular/core' ;
} from "@angular/core" ;
import { File } from "../../../models/File" ;
import { Tag } from "../../../models/Tag" ;
import { CdkVirtualScrollViewport } from "@angular/cdk/scrolling" ;
@ -14,9 +14,9 @@ import {TagService} from "../../../services/tag/tag.service";
import { FileService } from "../../../services/file/file.service" ;
@Component ( {
selector : 'app-file-edit' ,
templateUrl : './file-edit.component.html' ,
styleUrls : [ './file-edit.component.scss' ]
selector : "app-file-edit" ,
templateUrl : "./file-edit.component.html" ,
styleUrls : [ "./file-edit.component.scss" ]
} )
export class FileEditComponent implements OnInit , OnChanges {
@ -55,7 +55,8 @@ export class FileEditComponent implements OnInit, OnChanges {
if ( name . length > 0 ) {
const file = this . files [ 0 ] ;
console . log ( "Updating name to" , name ) ;
const responseFile = await this . fileService . updateFileName ( file , name ) ;
const responseFile = await this . fileService . updateFileName ( file ,
name ) ;
console . log ( "Updated name" ) ;
file . name = responseFile . name ;
this . resetFileNameInput ( ) ;
@ -64,7 +65,8 @@ export class FileEditComponent implements OnInit, OnChanges {
public async editTag ( tag : string ) : Promise < void > {
if ( tag . length > 0 ) {
let tagInstance = this . allTags . find ( t = > t . getNormalizedOutput ( ) === tag ) ;
let tagInstance = this . allTags . find (
t = > t . getNormalizedOutput ( ) === tag ) ;
if ( ! tagInstance ) {
tagInstance = ( await this . tagService . createTags ( [ tag ] ) ) [ 0 ] ;
@ -94,7 +96,8 @@ export class FileEditComponent implements OnInit, OnChanges {
} else {
removedTags . push ( tag . id ) ;
}
this . fileTags [ file . id ] = await this . tagService . changeFileTags ( file . id ,
this . fileTags [ file . id ] = await this . tagService . changeFileTags (
file . id ,
addedTags , removedTags ) ;
}
this . mapFileTagsToTagList ( ) ;
@ -105,7 +108,8 @@ export class FileEditComponent implements OnInit, OnChanges {
async addTag ( tag : Tag ) {
for ( const file of this . files ) {
if ( this . fileTags [ file . id ] . findIndex ( t = > t . id === tag . id ) < 0 ) {
this . fileTags [ file . id ] = await this . tagService . changeFileTags ( file . id ,
this . fileTags [ file . id ] = await this . tagService . changeFileTags (
file . id ,
[ tag . id ] , [ ] ) ;
}
}
@ -117,7 +121,8 @@ export class FileEditComponent implements OnInit, OnChanges {
public async removeTag ( tag : Tag ) {
for ( const file of this . files ) {
if ( this . fileTags [ file . id ] . findIndex ( t = > t . id === tag . id ) >= 0 ) {
this . fileTags [ file . id ] = await this . tagService . changeFileTags ( file . id ,
this . fileTags [ file . id ] = await this . tagService . changeFileTags (
file . id ,
[ ] , [ tag . id ] ) ;
}
}
@ -143,9 +148,11 @@ export class FileEditComponent implements OnInit, OnChanges {
for ( const file of this . files ) {
const fileTags = this . fileTags [ file . id ] ;
tags . push (
. . . fileTags . filter ( t = > tags . findIndex ( tag = > tag . id === t . id ) < 0 ) ) ;
. . . fileTags . filter (
t = > tags . findIndex ( tag = > tag . id === t . id ) < 0 ) ) ;
}
this . tags = tags . sort (
( a , b ) = > a . getNormalizedOutput ( ) . localeCompare ( b . getNormalizedOutput ( ) ) ) ;
( a , b ) = > a . getNormalizedOutput ( )
. localeCompare ( b . getNormalizedOutput ( ) ) ) ;
}
}