|
|
|
@ -6,6 +6,8 @@ import { Observable, Subject } from 'rxjs'; |
|
|
|
|
import { Script } from '../model/script'; |
|
|
|
|
import { Router, RouterModule } from '@angular/router'; |
|
|
|
|
import { ScriptService } from '../service/script.service'; |
|
|
|
|
import { Tag } from '../model/tag'; |
|
|
|
|
import { TagsService } from '../service/tags.service'; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-add-script', |
|
|
|
@ -22,17 +24,55 @@ export class AddScriptComponent { |
|
|
|
|
files: File[] = []; |
|
|
|
|
contentOfFiles: string[] = []; |
|
|
|
|
scriptToSend: Script | undefined; |
|
|
|
|
dropdownTagList: Tag[] = []; |
|
|
|
|
selectedTagList: Tag[] = []; |
|
|
|
|
dropdownSettings = {}; |
|
|
|
|
linkId: number | undefined; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private scriptService: ScriptService, |
|
|
|
|
private tagService: TagsService, |
|
|
|
|
private router: Router, |
|
|
|
|
private matIconRegistry: MatIconRegistry, |
|
|
|
|
private domSanitizer: DomSanitizer){ |
|
|
|
|
this.matIconRegistry.addSvgIcon('upload', this.domSanitizer.bypassSecurityTrustResourceUrl('../../assets/svg/upload.svg')), |
|
|
|
|
this.matIconRegistry.addSvgIcon('trash', this.domSanitizer.bypassSecurityTrustResourceUrl('../../assets/svg/trash.svg')) |
|
|
|
|
|
|
|
|
|
const navigation = this.router.getCurrentNavigation(); |
|
|
|
|
if(navigation){ |
|
|
|
|
const state = navigation.extras.state as { |
|
|
|
|
nextId: number |
|
|
|
|
}; |
|
|
|
|
this.linkId = state.nextId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void{ |
|
|
|
|
this.retrieveTags(); |
|
|
|
|
|
|
|
|
|
this.dropdownSettings = { |
|
|
|
|
singleSelection: false, |
|
|
|
|
idField: "tagId", |
|
|
|
|
textField: "nameTag", |
|
|
|
|
selectAllText: "Tout Sélectionner", |
|
|
|
|
unSelectAllText: "Déselectionner tout", |
|
|
|
|
itemsShowLimit: 3, |
|
|
|
|
allowSearchFilter: true |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public retrieveTags(){ |
|
|
|
|
this.tagService.getAllTags().subscribe( |
|
|
|
|
(response: Tag[]) => { |
|
|
|
|
this.dropdownTagList = response; |
|
|
|
|
}, |
|
|
|
|
(error: HttpErrorResponse) => { |
|
|
|
|
alert(error.message) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public isNewFile (){ |
|
|
|
|
this.newFile = true; |
|
|
|
|
} |
|
|
|
@ -55,7 +95,6 @@ export class AddScriptComponent { |
|
|
|
|
for(const item of event){ |
|
|
|
|
this.files.push(item); |
|
|
|
|
} |
|
|
|
|
console.log(this.files) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public displayText(index: number){ |
|
|
|
@ -79,14 +118,7 @@ export class AddScriptComponent { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public renderFileContent( value: string[] ) : void { |
|
|
|
|
console.log(value) |
|
|
|
|
//this.existingFileData = value;
|
|
|
|
|
this.newFileData = value[0]; |
|
|
|
|
console.log(this.existingFileData) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public seeCont(){ |
|
|
|
|
console.log(this.newFileData) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public formatBytes(bytes: number) { |
|
|
|
@ -101,7 +133,13 @@ export class AddScriptComponent { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public addScriptToCentral(){ |
|
|
|
|
if(this.nameOfExtension && this.nameOfFile && (this.existingFileData || this.newFileData)){ |
|
|
|
|
if(this.nameOfExtension && this.nameOfFile && this.linkId && this.selectedTagList && (this.existingFileData || this.newFileData)){ |
|
|
|
|
|
|
|
|
|
let listOfTags: String[] = [] |
|
|
|
|
this.selectedTagList.forEach(tag => { |
|
|
|
|
listOfTags.push(tag.nameTag); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const fullName = this.nameOfFile + "." + this.nameOfExtension; |
|
|
|
|
let tempData: String = ""; |
|
|
|
|
if(this.newFile && this.newFileData){ |
|
|
|
@ -114,7 +152,7 @@ export class AddScriptComponent { |
|
|
|
|
name: fullName, |
|
|
|
|
data: tempData, |
|
|
|
|
} |
|
|
|
|
this.scriptService.addOneScript(this.scriptToSend).subscribe( |
|
|
|
|
this.scriptService.addOneScript(this.scriptToSend, listOfTags, this.linkId).subscribe( |
|
|
|
|
() => { |
|
|
|
|
this.router.navigateByUrl('scriptmanagement'); |
|
|
|
|
}, |
|
|
|
@ -124,4 +162,21 @@ export class AddScriptComponent { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onItemSelect(item: any) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onSelectAll(items: any) { |
|
|
|
|
this.selectedTagList = items; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onItemDeselect(item: any){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onDeselectAll(items: any){ |
|
|
|
|
this.selectedTagList = []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|