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