add script and tags management

version_2
floxx2112 2 years ago
parent 1eb347b5f8
commit fbee9b6857
  1. 18
      package-lock.json
  2. 1
      package.json
  3. 4
      src/app/add-script/add-script.component.ts
  4. 2
      src/app/app-routing.module.ts
  5. 9
      src/app/app.module.ts
  6. 5
      src/app/model/tag.ts
  7. 23
      src/app/script-management/script-management.component.html
  8. 46
      src/app/script-management/script-management.component.ts
  9. 38
      src/app/service/tags.service.ts
  10. 61
      src/app/tags-management/tags-management.component.html
  11. 0
      src/app/tags-management/tags-management.component.scss
  12. 119
      src/app/tags-management/tags-management.component.ts

18
package-lock.json generated

@ -20,6 +20,7 @@
"@angular/router": "^15.1.0", "@angular/router": "^15.1.0",
"@tailwindcss/forms": "^0.5.3", "@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"ng-multiselect-dropdown": "^0.3.9",
"ng2-search-filter": "^0.5.1", "ng2-search-filter": "^0.5.1",
"ngx-dropzone": "^3.1.0", "ngx-dropzone": "^3.1.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
@ -8834,6 +8835,23 @@
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
"dev": true "dev": true
}, },
"node_modules/ng-multiselect-dropdown": {
"version": "0.3.9",
"resolved": "https://registry.npmjs.org/ng-multiselect-dropdown/-/ng-multiselect-dropdown-0.3.9.tgz",
"integrity": "sha512-y5fb8SVz8c59vEJGVe5XZ5ov6LZNoO8FqMxCBvpZKqw9tY1+f7UCDfILleOWPy8QMxO2Fpr8b+B+Az0zOS6b9g==",
"dependencies": {
"tslib": "^1.9.0"
},
"peerDependencies": {
"@angular/common": ">=2.0.0",
"@angular/core": ">=2.0.0"
}
},
"node_modules/ng-multiselect-dropdown/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/ng2-search-filter": { "node_modules/ng2-search-filter": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/ng2-search-filter/-/ng2-search-filter-0.5.1.tgz", "resolved": "https://registry.npmjs.org/ng2-search-filter/-/ng2-search-filter-0.5.1.tgz",

@ -22,6 +22,7 @@
"@angular/router": "^15.1.0", "@angular/router": "^15.1.0",
"@tailwindcss/forms": "^0.5.3", "@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"ng-multiselect-dropdown": "^0.3.9",
"ng2-search-filter": "^0.5.1", "ng2-search-filter": "^0.5.1",
"ngx-dropzone": "^3.1.0", "ngx-dropzone": "^3.1.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",

@ -50,7 +50,7 @@ export class AddScriptComponent {
public onFileDropped(event: any){ public onFileDropped(event: any){
this.readFile(event[0]).subscribe((output) => { this.readFile(event[0]).subscribe((output) => {
this.newFileData = output; this.existingFileData = output;
}) })
for(const item of event){ for(const item of event){
this.files.push(item); this.files.push(item);
@ -60,7 +60,7 @@ export class AddScriptComponent {
public displayText(index: number){ public displayText(index: number){
this.readFile(this.files[index]).subscribe((output) => { this.readFile(this.files[index]).subscribe((output) => {
this.newFileData = output; this.existingFileData = output;
}) })
} }

@ -8,6 +8,7 @@ import { CreateJoinsPageComponent } from './create-joins-page/create-joins-page.
import { ScriptManagementComponent } from './script-management/script-management.component'; import { ScriptManagementComponent } from './script-management/script-management.component';
import { AddScriptComponent } from './add-script/add-script.component'; import { AddScriptComponent } from './add-script/add-script.component';
import { EditScriptComponent } from './edit-script/edit-script.component'; import { EditScriptComponent } from './edit-script/edit-script.component';
import { TagsManagementComponent } from './tags-management/tags-management.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'schematab', component: SchemasTabComponent }, { path: 'schematab', component: SchemasTabComponent },
@ -18,6 +19,7 @@ const routes: Routes = [
{ path: 'scriptmanagement', component: ScriptManagementComponent }, { path: 'scriptmanagement', component: ScriptManagementComponent },
{ path: 'addscript', component: AddScriptComponent}, { path: 'addscript', component: AddScriptComponent},
{ path: 'editscript', component: EditScriptComponent}, { path: 'editscript', component: EditScriptComponent},
{ path: 'tagsmanagement', component: TagsManagementComponent},
]; ];
@NgModule({ @NgModule({

@ -28,6 +28,9 @@ import { AddScriptComponent } from './add-script/add-script.component';
import { DndDirective } from './directives/dnd.directive' import { DndDirective } from './directives/dnd.directive'
import { CustomFilterScript } from 'src/CustomFilterScript'; import { CustomFilterScript } from 'src/CustomFilterScript';
import { EditScriptComponent } from './edit-script/edit-script.component'; import { EditScriptComponent } from './edit-script/edit-script.component';
import { TagsManagementComponent } from './tags-management/tags-management.component';
import { NgMultiSelectDropDownModule } from 'ng-multiselect-dropdown';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -46,7 +49,8 @@ import { EditScriptComponent } from './edit-script/edit-script.component';
ScriptManagementComponent, ScriptManagementComponent,
AddScriptComponent, AddScriptComponent,
DndDirective, DndDirective,
EditScriptComponent EditScriptComponent,
TagsManagementComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -58,7 +62,8 @@ import { EditScriptComponent } from './edit-script/edit-script.component';
MatIconModule, MatIconModule,
FormsModule, FormsModule,
MatDialogModule, MatDialogModule,
MatProgressSpinnerModule MatProgressSpinnerModule,
NgMultiSelectDropDownModule
], ],
providers: [EmployeeService], providers: [EmployeeService],

@ -0,0 +1,5 @@
export interface Tag {
tagId: number;
nameTag: string;
descriptionTag: string;
}

@ -1,12 +1,13 @@
<div class="max-w-full rounded-2xl overflow-hidden shadow-lg bg-white"> <div class="max-w-full rounded-2xl overflow-hidden shadow-lg bg-white">
<div class="m-2 grid grid-cols-10 gap-4 justify-items-center"> <div class="m-2 grid grid-cols-12 gap-4 justify-items-center">
<div class="col-span-2 my-auto "> <div class="col-span-3 my-auto ">
<button class="flex text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 font-semibold py-2 px-4 rounded shadow m-2" (click)="getAllScripts()">Rafraichir</button> <button class="flex text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 font-semibold py-2 px-4 rounded shadow m-2" (click)="getAllScripts()">Rafraichir</button>
</div> </div>
<div class="col-span-6 my-auto text-2xl font-bold"> <div class="col-span-6 my-auto text-2xl font-bold">
|| Gestionnaire de Scripts || || Gestionnaire de Scripts ||
</div> </div>
<div class="col-span-2 my-auto"> <div class="col-span-3 my-auto flex">
<a routerLink="/tagsmanagement" class="flex text-black bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-red-100 dark:focus:ring-red-400 font-semibold py-2 px-4 rounded shadow m-2" >Gérer les Tags</a>
<a routerLink="/addscript" class="flex text-black bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-red-100 dark:focus:ring-red-400 font-semibold py-2 px-4 rounded shadow m-2" >Ajouter un Script</a> <a routerLink="/addscript" class="flex text-black bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-red-100 dark:focus:ring-red-400 font-semibold py-2 px-4 rounded shadow m-2" >Ajouter un Script</a>
</div> </div>
@ -17,7 +18,21 @@
<div class="col-span-2 rounded-lg overflow-hidden shadow-lg bg-slate-100 border-solid border-orange-400 border-2 p-4"> <div class="col-span-2 rounded-lg overflow-hidden shadow-lg bg-slate-100 border-solid border-orange-400 border-2 p-4">
<div class="flex space-x-2"> <div class="flex space-x-2">
<input [(ngModel)]="filterScriptName" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Rechercher..."> <input [(ngModel)]="filterScriptName" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Rechercher...">
<input type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Tags..."> <!-- <input type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Tags..."> -->
</div>
<div>
<ng-multiselect-dropdown
[placeholder]="'Selectionner les Tags'"
[settings]="dropdownSettings"
[data]="dropdownTagList"
[(ngModel)]="selectedTagList"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
(onDeSelect)="onItemDeselect($event)"
(onDeSelectAll)="onDeselectAll($event)"
>
</ng-multiselect-dropdown>
</div> </div>
<div class="overflow-y-auto h-96"> <div class="overflow-y-auto h-96">
<div class="grid grid-cols-2"> <div class="grid grid-cols-2">

@ -5,6 +5,8 @@ import { Script } from '../model/script';
import { MatIconRegistry } from '@angular/material/icon'; import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { Router, NavigationExtras } from '@angular/router'; import { Router, NavigationExtras } from '@angular/router';
import { TagsService } from '../service/tags.service';
import { Tag } from '../model/tag';
@Component({ @Component({
@ -17,9 +19,13 @@ export class ScriptManagementComponent implements OnInit {
textTo: String | undefined; textTo: String | undefined;
allScripts: Script[] = []; allScripts: Script[] = [];
filterScriptName: any; filterScriptName: any;
dropdownTagList: Tag[] = [];
selectedTagList: Tag[] = [];
dropdownSettings = {};
constructor( constructor(
private router: Router, private router: Router,
private tagService: TagsService,
private scriptService: ScriptService, private scriptService: ScriptService,
private matIconRegistry: MatIconRegistry, private matIconRegistry: MatIconRegistry,
private domSanitizer: DomSanitizer private domSanitizer: DomSanitizer
@ -30,7 +36,19 @@ export class ScriptManagementComponent implements OnInit {
} }
ngOnInit(): void{ ngOnInit(): void{
this.getAllScripts(); this.getAllScripts();
this.retrieveTags();
this.dropdownSettings = {
singleSelection: false,
idField: "tagId",
textField: "nameTag",
selectAllText: "Tout Sélectionner",
unSelectAllText: "Déselectionner tout",
itemsShowLimit: 3,
allowSearchFilter: true
};
} }
public displayText(text: String){ public displayText(text: String){
@ -39,6 +57,34 @@ export class ScriptManagementComponent implements OnInit {
} }
} }
public retrieveTags(){
this.tagService.getAllTags().subscribe(
(response: Tag[]) => {
this.dropdownTagList = response;
},
(error: HttpErrorResponse) => {
alert(error.message)
});
}
onItemSelect(item: any) {
}
onSelectAll(items: any) {
this.selectedTagList = items;
}
onItemDeselect(item: any){
}
onDeselectAll(items: any){
this.selectedTagList = [];
}
public editScript(script: Script){ public editScript(script: Script){
const navigationExtras: NavigationExtras = { const navigationExtras: NavigationExtras = {
state: { state: {

@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment.development';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Tag } from '../model/tag';
@Injectable({
providedIn: 'root'
})
export class TagsService {
private apiServerUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) { }
public addTag(tag: Tag){
return this.http.post<void>(`${this.apiServerUrl}/api/tag/add`, tag);
}
public updateTag(prevName: string, tag: Tag){
return this.http.put<void>(`${this.apiServerUrl}/api/tag/update/${prevName}`, tag);
}
public getTag(tagId: Number): Observable<Tag>{
return this.http.get<Tag>(`${this.apiServerUrl}/api/tag/${tagId}`);
}
public getAllTags(): Observable<Tag[]>{
return this.http.get<Tag[]>(`${this.apiServerUrl}/api/tags/all`);
}
public deleteTag(tagName: String){
return this.http.delete<void>(`${this.apiServerUrl}/api/tag/delete/${tagName}`);
}
public deleteAllTags(){
return this.http.delete<void>(`${this.apiServerUrl}/api/tags/deleteAll`);
}
}

@ -0,0 +1,61 @@
<div class="my-4">
<div class="text-center rounded-lg overflow-hidden shadow-lg bg-white p-4 ">
<div class="text-2xl font-bold">Gestion des Tags</div>
<div class="grid grid-cols-3 gap-4 mt-2">
<button class="text-black bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-red-100 font-semibold py-2 px-2 rounded shadow mx-2" (click)="addPress = !addPress">Ajouter un Tag</button>
<input [(ngModel)]="filterTag" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Rechercher...">
<button class="text-white bg-gradient-to-br from-pink-500 to-orange-400 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-pink-200 font-semibold py-2 px- rounded shadow mx-2" (click)="deleteAllTags()" disabled>Supprimer tous les Tags</button>
</div>
<div *ngIf="addPress">
<div class="bg-orange-400 w-full h-2 overflow-hidden my-4 rounded-lg"></div>
<div class="grid grid-cols-2 gap-4">
<div>
<div class="text-lg font-semibold">Nom du Tag : </div>
<input [(ngModel)]="nameOfTag" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Taper le nom ici...">
</div>
<div>
<div class="text-lg font-semibold">Description du Tag : </div>
<input [(ngModel)]="descOfTag" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Taper la description ici...">
</div>
</div>
<button class="text-white bg-gradient-to-br from-green-400 to-blue-600 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-green-200 font-semibold py-2 px-2 rounded shadow mx-2 mt-4" (click)="addTag()">Valider</button>
</div>
<div class="bg-orange-400 w-full h-2 overflow-hidden my-4 rounded-lg"></div>
<div *ngIf="modifyPress">
<div class="grid grid-cols-2 gap-4">
<div>
<div class="text-lg font-semibold">Nom du Tag : </div>
<div>{{ previousName }}</div>
<div class="text-lg font-semibold">Nouveau nom : </div>
<input [(ngModel)]="modifyName" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Taper le nom ici...">
</div>
<div>
<div class="text-lg font-semibold">Description du Tag : </div>
<div>{{ previousDesc }}</div>
<div class="text-lg font-semibold">Nouvelle description : </div>
<input [(ngModel)]="modifyDesc" type="text" class="block w-full my-2 pl-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-slate-800 focus:border-slate-800" placeholder="Taper la description ici...">
</div>
</div>
<button class="text-white bg-gradient-to-br from-green-400 to-blue-600 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-green-200 font-semibold py-2 px-2 rounded shadow mx-2 my-4" (click)="modifyTag()">Valider</button>
</div>
<div class="grid grid-cols-4 gap-4">
<div *ngFor="let tag of allTags | filter: filterTag" class="rounded-2xl overflow-hidden shadow-lg bg-slate-800 p-2">
<div class="text-white font-bold">Nom du Tag : {{ tag.nameTag }}</div>
<div class="text-white">{{ tag.descriptionTag }}</div>
<div class="flex justify-between my-2">
<button class="text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 font-semibold py-2 px-2 rounded shadow mx-2" (click)="pressModifyBtn(tag.tagId, tag.nameTag, tag.descriptionTag)">Modifier</button>
<button class="text-black bg-gradient-to-r from-teal-200 to-lime-200 hover:bg-gradient-to-l hover:from-teal-200 hover:to-lime-200 focus:ring-4 focus:outline-none focus:ring-lime-200 font-semibold py-2 px-2 rounded shadow mx-2" (click)="deleleTag(tag)">Supprimer</button>
</div>
</div>
</div>
</div>
</div>

@ -0,0 +1,119 @@
import { Component, OnInit } from '@angular/core';
import { TagsService } from '../service/tags.service';
import { HttpErrorResponse } from '@angular/common/http';
import { Tag } from '../model/tag';
@Component({
selector: 'app-tags-management',
templateUrl: './tags-management.component.html',
styleUrls: ['./tags-management.component.scss']
})
export class TagsManagementComponent implements OnInit{
allTags: Tag[]= [];
filterTag: any;
nameOfTag: string | undefined;
descOfTag: string | undefined;
addPress: boolean = false;
modifyPress: boolean = false;
previousId: number | undefined
previousName: String | undefined;
previousDesc: String | undefined;
modifyName: string | undefined;
modifyDesc: string | undefined;
constructor(private tagService: TagsService){}
ngOnInit(): void{
this.retrieveTags();
}
public retrieveTags(){
this.tagService.getAllTags().subscribe(
(response: Tag[]) => {
console.log(response)
this.allTags = response;
},
(error: HttpErrorResponse) => {
alert(error.message)
});
}
public addTag(){
if(this.nameOfTag && this.descOfTag){
let tag: Tag = {
tagId: this.allTags[this.allTags.length - 1].tagId + 1,
nameTag: this.nameOfTag,
descriptionTag: this.descOfTag
}
this.tagService.addTag(tag).subscribe(
() => {
this.addPress = false;
this.nameOfTag =undefined;
this.descOfTag = undefined;
this.retrieveTags();
},
(error: HttpErrorResponse) => {
alert(error.message)
});
}
}
public modifyTag(){
console.log(this.previousId, this.previousName, this.previousDesc, this.modifyName, this.modifyDesc)
if(this.previousName && this.previousDesc && this.previousId && this.modifyName && this.modifyDesc){
let modifyTag: Tag = {
tagId: this.previousId,
nameTag: this.modifyName.toString(),
descriptionTag: this.modifyDesc.toString()
}
console.log(this.previousName, modifyTag)
this.tagService.updateTag(this.previousName.toString(), modifyTag).subscribe(
() => {
this.modifyPress = false;
this.previousId = undefined;
this.previousName = undefined;
this.previousDesc = undefined;
this.modifyName = undefined;
this.modifyDesc = undefined;
this.retrieveTags();
},
(error: HttpErrorResponse) => {
alert(error.message)
});
}
}
public deleleTag(tag: Tag){
this.tagService.deleteTag(tag.nameTag).subscribe(
() => {
this.retrieveTags();
},
(error: HttpErrorResponse) => {
alert(error.message)
});
}
public deleteAllTags(){
if(window.confirm('Êtes-vous sûr de vouloir supprimer tous les tags ?')){
this.tagService.deleteAllTags().subscribe(
() => {
console.log("c supp")
},
(error: HttpErrorResponse) => {
alert(error.message)
}
);
}
}
public pressModifyBtn(id: number, name: string, desc: string){
this.previousId = id;
this.previousName = name;
this.previousDesc = desc;
this.modifyName = name;
this.modifyDesc = desc;
this.modifyPress = !this.modifyPress;
}
}
Loading…
Cancel
Save