From 0bddd4917fa3195e59bbd30820680c380c8593e9 Mon Sep 17 00:00:00 2001 From: "kelly.nguyen" <kelly.nguyen@etu.hesge.ch> Date: Mon, 5 Feb 2024 21:27:16 +0100 Subject: [PATCH] get information of assignments with json --- AngularApp/package-lock.json | 100 +++++++++++++++++- AngularApp/package.json | 15 +-- AngularApp/src/app/app.routing.ts | 2 + .../card-assignment.component.html | 4 +- .../card-assignment.component.ts | 2 +- .../exercise-student.component.ts | 22 ++-- AngularApp/src/app/model/assignment.ts | 9 +- .../app/table-list/table-list.component.html | 14 +-- .../app/table-list/table-list.component.ts | 50 ++++----- .../app/user-list/user-list.component.html | 65 +++++++----- .../src/app/user-list/user-list.component.ts | 12 ++- AngularApp/src/services/assignment.service.ts | 4 +- AngularApp/src/services/user.service.ts | 8 +- 13 files changed, 216 insertions(+), 91 deletions(-) diff --git a/AngularApp/package-lock.json b/AngularApp/package-lock.json index c9a45c2..9b4df25 100644 --- a/AngularApp/package-lock.json +++ b/AngularApp/package-lock.json @@ -34,6 +34,7 @@ "hammerjs": "2.0.8", "jquery": "3.6.0", "moment": "2.29.1", + "mysql2": "^3.9.1", "perfect-scrollbar": "1.5.5", "popper.js": "1.16.1", "rxjs": "~7.5.0", @@ -46,12 +47,12 @@ "@angular/cli": "~14.2.7", "@angular/compiler-cli": "^14.2.0", "@angular/language-service": "14.2.0", - "@types/bootstrap": "4.5.0", + "@types/bootstrap": "^4.5.0", "@types/chartist": "0.11.1", "@types/google.maps": "3.47.4", "@types/jasmine": "~4.0.0", "@types/jasminewd2": "~2.0.10", - "@types/jquery": "3.5.6", + "@types/jquery": "^3.5.6", "@types/node": "^17.0.21", "codelyzer": "6.0.2", "jasmine-core": "~4.4.0", @@ -5781,6 +5782,14 @@ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", "dev": true }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -7389,6 +7398,14 @@ "node": ">=10" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -8362,6 +8379,11 @@ "node": ">=0.10.0" } }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==" + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -9575,6 +9597,11 @@ "node": ">=8.0" } }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -9981,6 +10008,62 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "node_modules/mysql2": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.1.tgz", + "integrity": "sha512-3njoWAAhGBYy0tWBabqUQcLtczZUxrmmtc2vszQUekg3kTJyZ5/IeLC3Fo04u6y6Iy5Sba7pIIa2P/gs8D3ZeQ==", + "dependencies": { + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/mysql2/node_modules/lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", + "engines": { + "node": ">=16.14" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", + "dependencies": { + "lru-cache": "^7.14.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/named-placeholders/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "engines": { + "node": ">=12" + } + }, "node_modules/nanoid": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", @@ -12884,6 +12967,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, "node_modules/serialize-javascript": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", @@ -13266,6 +13354,14 @@ "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", "dev": true }, + "node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/sshpk": { "version": "1.18.0", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", diff --git a/AngularApp/package.json b/AngularApp/package.json index 121600e..0fe7fc1 100644 --- a/AngularApp/package.json +++ b/AngularApp/package.json @@ -42,26 +42,26 @@ "hammerjs": "2.0.8", "jquery": "3.6.0", "moment": "2.29.1", + "mysql2": "^3.9.1", "perfect-scrollbar": "1.5.5", "popper.js": "1.16.1", "rxjs": "~7.5.0", "tslib": "^2.3.0", - "zone.js": "~0.11.4", - "web-animations-js": "2.3.2" + "web-animations-js": "2.3.2", + "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "^14.2.7", "@angular/cli": "~14.2.7", "@angular/compiler-cli": "^14.2.0", "@angular/language-service": "14.2.0", + "@types/bootstrap": "^4.5.0", + "@types/chartist": "0.11.1", + "@types/google.maps": "3.47.4", "@types/jasmine": "~4.0.0", "@types/jasminewd2": "~2.0.10", + "@types/jquery": "^3.5.6", "@types/node": "^17.0.21", - "@types/bootstrap": "4.5.0", - "@types/chartist": "0.11.1", - "@types/google.maps": "3.47.4", - "@types/jquery": "3.5.6", - "sass": "1.32.13", "codelyzer": "6.0.2", "jasmine-core": "~4.4.0", "jasmine-spec-reporter": "~7.0.0", @@ -72,6 +72,7 @@ "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", "protractor": "7.0.0", + "sass": "1.32.13", "ts-node": "~10.9.1", "typescript": "~4.7.2" } diff --git a/AngularApp/src/app/app.routing.ts b/AngularApp/src/app/app.routing.ts index 0b160a0..c364910 100644 --- a/AngularApp/src/app/app.routing.ts +++ b/AngularApp/src/app/app.routing.ts @@ -4,6 +4,8 @@ import { BrowserModule } from '@angular/platform-browser'; import { Routes, RouterModule } from '@angular/router'; import { AdminLayoutComponent } from './layouts/admin-layout/admin-layout.component'; +import * as bootstrap from "bootstrap"; +import * as $ from "jquery"; const routes: Routes =[ { diff --git a/AngularApp/src/app/card-assignment/card-assignment.component.html b/AngularApp/src/app/card-assignment/card-assignment.component.html index 119f08e..f89a0eb 100644 --- a/AngularApp/src/app/card-assignment/card-assignment.component.html +++ b/AngularApp/src/app/card-assignment/card-assignment.component.html @@ -1,4 +1,4 @@ -<div class="card card-stats"> +<!-- <div class="card card-stats"> <div class="card-header card-header-warning card-header-icon"> <div class="card-icon"> <i class="material-icons">content_paste</i> @@ -10,4 +10,4 @@ <div class="card-footer"> <p>{{assgn.language}}</p> </div> -</div> \ No newline at end of file +</div> --> \ No newline at end of file diff --git a/AngularApp/src/app/card-assignment/card-assignment.component.ts b/AngularApp/src/app/card-assignment/card-assignment.component.ts index f9ba190..7ba9179 100644 --- a/AngularApp/src/app/card-assignment/card-assignment.component.ts +++ b/AngularApp/src/app/card-assignment/card-assignment.component.ts @@ -8,7 +8,7 @@ import { Assignment } from 'app/model/assignment'; styleUrls: ['./card-assignment.component.scss'], }) export class CardAssignmentComponent implements OnInit { - @Input() assgn : Assignment; + // @Input() assgn : Assignment; constructor() { } diff --git a/AngularApp/src/app/exercise-student/exercise-student.component.ts b/AngularApp/src/app/exercise-student/exercise-student.component.ts index 59f7d85..cccdd5f 100644 --- a/AngularApp/src/app/exercise-student/exercise-student.component.ts +++ b/AngularApp/src/app/exercise-student/exercise-student.component.ts @@ -19,16 +19,16 @@ export class ExerciseStudentComponent implements OnInit { ]; dataAssignment : Assignment [] = [ - { - title: 'TCP', - description: 'Technique de compilation', - language: 'Java' - }, - { - title: 'Virtualisation', - description: 'Comprehension des VM', - language: 'C' - }, + // { + // title: 'TCP', + // description: 'Technique de compilation', + // language: 'Java' + // }, + // { + // title: 'Virtualisation', + // description: 'Comprehension des VM', + // language: 'C' + // }, ]; displayedColumns: string[] = [ @@ -212,7 +212,7 @@ export class ExerciseStudentComponent implements OnInit { filterBy(ob: HTMLSelectElement) { if (ob.value) { - this.assignmentFilter = this.dataAssignment.filter(p => p.language === ob.value); + // this.assignmentFilter = this.dataAssignment.filter(p => p.language === ob.value); } if (ob.value == 'All') { this.assignmentFilter = this.dataAssignment; diff --git a/AngularApp/src/app/model/assignment.ts b/AngularApp/src/app/model/assignment.ts index 4539f2d..e401fff 100644 --- a/AngularApp/src/app/model/assignment.ts +++ b/AngularApp/src/app/model/assignment.ts @@ -1,5 +1,8 @@ export interface Assignment { - title : string, - description : string, - language : string + name : string, + gitLabId: string, + gitlabCreationInfo : string, + gitlabLastInfo : string, + gitlabLink : string, + gitlabLastInfoDate : string, } \ No newline at end of file diff --git a/AngularApp/src/app/table-list/table-list.component.html b/AngularApp/src/app/table-list/table-list.component.html index 1a59757..7eeb835 100644 --- a/AngularApp/src/app/table-list/table-list.component.html +++ b/AngularApp/src/app/table-list/table-list.component.html @@ -16,13 +16,15 @@ </th> </thead> <tbody> - <tr *ngFor="let row of rows"> - <td>{{row.assignment.title}}</td> - <td>{{row.assignment.description}}</td> - <td>{{row.nbOfSuccess}}</td> - <td>{{row.nbExerciseCreated}}</td> + <tr *ngFor="let assignment of assignments"> + <td>{{assignment.gitlabId}}</td> + <td>{{assignment.name}}</td> + <td>{{creationInfo.description}}</td> + <td>{{creationInfo.created_at}}</td> + <td>{{lastInfo.updated_at}}</td> + <td>{{assignment.gitlabLink}}</td> <td> - <button (click)="deleteEnonce(row.assignment.title)" class="btn btn-outline-danger">Delete</button> + <button class="btn btn-outline-danger">Delete</button> </td> </tr> </tbody> diff --git a/AngularApp/src/app/table-list/table-list.component.ts b/AngularApp/src/app/table-list/table-list.component.ts index 4f52635..8ad9060 100644 --- a/AngularApp/src/app/table-list/table-list.component.ts +++ b/AngularApp/src/app/table-list/table-list.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit } from '@angular/core'; +import { Assignment } from 'app/model/assignment'; import { Enonce } from 'app/model/enonce'; +import { AssignmentService } from 'services/assignment.service'; @Component({ selector: 'app-table-list', @@ -7,37 +9,29 @@ import { Enonce } from 'app/model/enonce'; styleUrls: ['./table-list.component.css'] }) export class TableListComponent implements OnInit { + assignments : Assignment[] = [] + data : [] = [] + creationInfo : JSON + lastInfo : JSON + constructor(private service : AssignmentService) { } - constructor() { } + headers : string[] = ['Gitlab ID', 'Name', 'Description', 'gitlabCreationInfo', 'Last Update', 'gitlabLink', 'Options']; - headers : string[] = ['Assignment', 'Description', 'Number of success', 'Exercises created', 'Options']; - - rows : Enonce[] = [ - { - assignment : { - title: 'TCP', - description: 'Technique de compilation', - language: 'Java' - }, - nbOfSuccess : 2, - nbExerciseCreated : 10 - }, - { - assignment : { - title: 'Virtualisation', - description: 'Comprehension des VM', - language: 'C' - }, - nbOfSuccess : 0, - nbExerciseCreated : 15 - } - ] - - deleteEnonce(title) { - this.rows = this.rows.filter((enonce) => enonce.assignment.title !== title); - console.log(this.rows); - } ngOnInit() { + this.service.getAssignments().subscribe((assignment) => { + this.assignments = assignment + for (let i = 0; i < this.assignments.length; i++) { + this.creationInfo = JSON.parse(this.assignments[i].gitlabCreationInfo) + this.lastInfo = JSON.parse(this.assignments[i].gitlabLastInfo) + console.log(this.creationInfo) + console.log(this.lastInfo) + } + }) + + } + delAssignment() { + + } } diff --git a/AngularApp/src/app/user-list/user-list.component.html b/AngularApp/src/app/user-list/user-list.component.html index 1c0997b..69e8d41 100644 --- a/AngularApp/src/app/user-list/user-list.component.html +++ b/AngularApp/src/app/user-list/user-list.component.html @@ -1,18 +1,18 @@ <div class="main-content"> - <div class="container-fluid"> - <div class="row"> - <div class="col-md-12"> - <div class="card"> - <div class="card-header card-header-danger"> - <h4 class="card-title ">Liste utilisateurs</h4> - </div> - <div class="card-body"> - <div class="table-responsive"> - <table class="table"> - <thead class=" text-primary"> + <div class="container-fluid"> + <div class="row"> + <div class="col-md-12"> + <div class="card"> + <div class="card-header card-header-danger"> + <h4 class="card-title ">Liste utilisateurs</h4> + </div> + <div class="card-body"> + <div class="table-responsive"> + <table class="table"> + <thead class=" text-primary"> <th *ngFor="let h of headers">{{h}}</th> - </thead> - <tbody> + </thead> + <tbody> <tr *ngFor="let user of users"> <td>{{ user.gitlabUsername }}</td> <td> @@ -21,19 +21,36 @@ <mat-option *ngFor="let opt of options" value="{{opt}}">{{opt}}</mat-option> </mat-select> </mat-form-field> - <p>You selected: {{ user.role }}</p> </td> <td> - <button (click)="updUser(user.id)" class="btn btn-outline-info">Modify</button> + <button id="btnUpdModal" (click)="updateRole(user.id, user.role)" class="btn btn-outline-info">Update Role</button> + <div class="modal" id="updModal" tabindex="-1" role="dialog"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title">Confirmation</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body"> + Votre role a été modifié + </div> + <!-- <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button> + <button type="button" class="btn btn-danger">Supprimer</button> + </div> --> + </div> + </div> + </div> </td> </tr> </tbody> - </table> - </div> - </div> - </div> - </div> - </div> - </div> - </div> - \ No newline at end of file + </table> + </div> + </div> + </div> + </div> + </div> + </div> +</div> diff --git a/AngularApp/src/app/user-list/user-list.component.ts b/AngularApp/src/app/user-list/user-list.component.ts index 5ec424f..28d797d 100644 --- a/AngularApp/src/app/user-list/user-list.component.ts +++ b/AngularApp/src/app/user-list/user-list.component.ts @@ -22,8 +22,12 @@ export class UserListComponent implements OnInit { }); } - // deleteEnonce(id) { - // this.rows = this.rows.filter((enonce) => enonce.assignment.title !== title); - // console.log(this.rows); - // } + updateRole(id : number, role : string) : void { + this.userService.updateUserRole(id, role).subscribe((upd) => { + if (upd.serverStatus == 2) { + $('#updModal').modal('show'); + } + }) + + } } diff --git a/AngularApp/src/services/assignment.service.ts b/AngularApp/src/services/assignment.service.ts index 370991c..df36267 100644 --- a/AngularApp/src/services/assignment.service.ts +++ b/AngularApp/src/services/assignment.service.ts @@ -7,11 +7,11 @@ import { Observable } from 'rxjs'; providedIn: 'root' }) export class AssignmentService { - private baseUrl = 'http://localhost:3000'; + private baseUrl = 'http://192.168.1.156:3000'; constructor(private http: HttpClient) {} - getUsers(): Observable<Assignment[]> { + getAssignments(): Observable<Assignment[]> { return this.http.get<Assignment[]>(`${this.baseUrl}/assignments`); } } diff --git a/AngularApp/src/services/user.service.ts b/AngularApp/src/services/user.service.ts index ece9138..493b64f 100644 --- a/AngularApp/src/services/user.service.ts +++ b/AngularApp/src/services/user.service.ts @@ -8,11 +8,17 @@ import { User } from 'app/model/user'; }) export class UserService { - private baseUrl = 'http://localhost:3000'; + private baseUrl = 'http://192.168.1.156:3000'; constructor(private http: HttpClient) {} getUsers(): Observable<User[]> { return this.http.get<User[]>(`${this.baseUrl}/users`); } + updateUserRole(userId: number, newRole: string): Observable<any> { + const body = { role: newRole }; + const url = `${this.baseUrl}/users/${userId}`; + + return this.http.put(url, body); + } } -- GitLab