diff options
author | jm.bardallo <juanmanuel.bardallo@sic.uhu.es> | 2019-05-17 11:41:01 +0200 |
---|---|---|
committer | jm.bardallo <juanmanuel.bardallo@sic.uhu.es> | 2019-05-17 11:41:01 +0200 |
commit | 06432724ce17c0dedbe540cc4e3d8a621705014e (patch) | |
tree | 794b3bf9fab66f5101d2bf9c449ace372e97b0d2 | |
parent | e157720ae79fb76cdbfc6eff738ff1797c7cb722 (diff) |
Solucionado pantalla de perfil software
Revisados los comandos para enviar el parametro sendConfig
15 files changed, 269 insertions, 66 deletions
diff --git a/admin/WebConsole3/frontend/src/app/api/software-component.service.ts b/admin/WebConsole3/frontend/src/app/api/software-component.service.ts index b154d41a..515f1cb4 100644 --- a/admin/WebConsole3/frontend/src/app/api/software-component.service.ts +++ b/admin/WebConsole3/frontend/src/app/api/software-component.service.ts @@ -14,7 +14,7 @@ import {ResourceService} from "globunet-angular/core/providers/api/resource.serv export class SoftwareComponentService extends ResourceService<SoftwareComponent> { constructor(http: HttpClient){ - super(http, environment.API_URL,"softwarecomponents", new SoftwareComponentSerializer()); + super(http, environment.API_URL,"softwares", new SoftwareComponentSerializer()); } } diff --git a/admin/WebConsole3/frontend/src/app/api/software-type.service.ts b/admin/WebConsole3/frontend/src/app/api/software-type.service.ts index ccc6eb8f..1c250b91 100644 --- a/admin/WebConsole3/frontend/src/app/api/software-type.service.ts +++ b/admin/WebConsole3/frontend/src/app/api/software-type.service.ts @@ -1,20 +1,36 @@ -import { Injectable } from '@angular/core'; -import { HttpClient} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; -import { environment } from '../../environments/environment'; -import { SoftwareType } from "../model/software-type"; -import { SoftwareTypeSerializer } from "../serializer/software-type.serializer"; +import {environment} from '../../environments/environment'; +import {SoftwareType} from '../model/software-type'; +import {SoftwareTypeSerializer} from '../serializer/software-type.serializer'; -import {ResourceService} from "globunet-angular/core/providers/api/resource.service"; +import {ResourceService} from 'globunet-angular/core/providers/api/resource.service'; +import {QueryOptions} from 'globunet-angular/core/providers/api/query-options'; +import {Observable} from 'rxjs'; +import {OgCommonService} from '../service/og-common.service'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class SoftwareTypeService extends ResourceService<SoftwareType> { - constructor(http: HttpClient){ - super(http, environment.API_URL,"softwaretypes", new SoftwareTypeSerializer()); - } + constructor(http: HttpClient, private ogCommonService: OgCommonService) { + super(http, environment.API_URL, 'softwaretypes', new SoftwareTypeSerializer()); + } + + list(queryOptions?: QueryOptions): Observable<SoftwareType[]> { + return new Observable<SoftwareType[]>((observer) => { + this.ogCommonService.loadEngineConfig().subscribe( + data => { + observer.next(data.constants.sofwaretypes); + }, + error => { + observer.error(error); + } + ); + }); + } } diff --git a/admin/WebConsole3/frontend/src/app/core/header-inner/header-inner.component.html b/admin/WebConsole3/frontend/src/app/core/header-inner/header-inner.component.html index 31b4286d..23cdb7e0 100644 --- a/admin/WebConsole3/frontend/src/app/core/header-inner/header-inner.component.html +++ b/admin/WebConsole3/frontend/src/app/core/header-inner/header-inner.component.html @@ -9,7 +9,7 @@ </mk-dropdown-toggle> <mk-dropdown-menu> <li class="header" *ngIf="executionTasks.length > 0"> - <span translate="you_have_x_exectution_taks" translate-values="{values: executionTasks.length}"></span> + <span translate="you_have_x_exectution_taks" [translateParams]="{values: executionTasks.length}"></span> </li> <li *ngIf="executionTasks.length > 0"> <!-- inner menu: contains the actual data --> @@ -21,7 +21,7 @@ </a> <a href="javascript:void(0)" (click)="relaunchExecutionTask(task)" class="btn btn-sm pull-right small-box-footer"> <i class="fa fa-refresh"></i> - </a>A + </a> </div> <a href="javascript:void(0)" (click)="ogCommandsService.execute('REALTIME_LOG', {clientIp: task.client.ip})"> <i class="fa fa-warning text-yellow"></i> {{task.client.name}} ({{task.client.ip}})<br>{{task.commandType|translate}} diff --git a/admin/WebConsole3/frontend/src/app/form-type/software-profile.form-type.ts b/admin/WebConsole3/frontend/src/app/form-type/software-profile.form-type.ts new file mode 100644 index 00000000..baa16afe --- /dev/null +++ b/admin/WebConsole3/frontend/src/app/form-type/software-profile.form-type.ts @@ -0,0 +1,12 @@ +import {GlobunetFormType} from './globunet.form-type'; +import {SoftwareProfile} from '../model/software-profile'; + + +export class SoftwareProfileFormType extends GlobunetFormType { + getForm() { + const formType = GlobunetFormType.getForm(new SoftwareProfile()); + this.setFieldType(formType, 'description', 'textarea'); + this.removeField(formType, 'softwares'); + return formType; + } +} diff --git a/admin/WebConsole3/frontend/src/app/model/command.ts b/admin/WebConsole3/frontend/src/app/model/command.ts index 2c5697aa..5fc44734 100644 --- a/admin/WebConsole3/frontend/src/app/model/command.ts +++ b/admin/WebConsole3/frontend/src/app/model/command.ts @@ -1,9 +1,10 @@ import { Resource } from 'globunet-angular/core/models/api/resource'; -export class Excecution { +export class Execution { script = ''; clients = ''; type = ''; + sendConfig = false; } export class Command extends Resource { diff --git a/admin/WebConsole3/frontend/src/app/model/software-profile.ts b/admin/WebConsole3/frontend/src/app/model/software-profile.ts index 5b3ba732..6d411f20 100644 --- a/admin/WebConsole3/frontend/src/app/model/software-profile.ts +++ b/admin/WebConsole3/frontend/src/app/model/software-profile.ts @@ -1,6 +1,8 @@ -import { Resource } from 'globunet-angular/core/models/api/resource';
-
-export class SoftwareProfile extends Resource {
- description: string;
- comments: string;
-}
+import { Resource } from 'globunet-angular/core/models/api/resource'; +import {SoftwareComponent} from './software-component'; + +export class SoftwareProfile extends Resource { + description = ''; + comments = ''; + public softwares: SoftwareComponent[] = []; +} diff --git a/admin/WebConsole3/frontend/src/app/pages/command/create-image-command/create-image-command.component.ts b/admin/WebConsole3/frontend/src/app/pages/command/create-image-command/create-image-command.component.ts index 8f018e33..e97d20fa 100644 --- a/admin/WebConsole3/frontend/src/app/pages/command/create-image-command/create-image-command.component.ts +++ b/admin/WebConsole3/frontend/src/app/pages/command/create-image-command/create-image-command.component.ts @@ -10,7 +10,7 @@ import {User} from '../../../model/user'; import {OGCommandsService} from '../../../service/og-commands.service'; import {CommandService} from '../../../api/command.service'; import {Image} from '../../../model/image'; -import {Command, Excecution} from '../../../model/command'; +import {Command, Execution} from '../../../model/command'; import {Client, Partition} from '../../../model/client'; import {Repository} from '../../../model/repository'; import {RepositoryService} from '../../../api/repository.service'; @@ -26,7 +26,7 @@ export class CreateImageCommandComponent implements OnInit { private readonly user: User; private constants: any; public repositories: Repository[]; - public execution = new Excecution(); + public execution = new Execution(); public commands: Command[] = []; public client: Client; public images = []; diff --git a/admin/WebConsole3/frontend/src/app/pages/command/delete-cache-image-command/delete-cache-image-command.component.ts b/admin/WebConsole3/frontend/src/app/pages/command/delete-cache-image-command/delete-cache-image-command.component.ts index efc14d6d..fb238868 100644 --- a/admin/WebConsole3/frontend/src/app/pages/command/delete-cache-image-command/delete-cache-image-command.component.ts +++ b/admin/WebConsole3/frontend/src/app/pages/command/delete-cache-image-command/delete-cache-image-command.component.ts @@ -10,7 +10,7 @@ import {User} from '../../../model/user'; import {OGCommandsService} from '../../../service/og-commands.service'; import {CommandService} from '../../../api/command.service'; import {Image} from '../../../model/image'; -import {Command, Excecution} from '../../../model/command'; +import {Command, Execution} from '../../../model/command'; import {Client} from '../../../model/client'; import {Repository} from '../../../model/repository'; import {RepositoryService} from '../../../api/repository.service'; @@ -25,7 +25,7 @@ export class DeleteCacheImageCommandComponent implements OnInit { private readonly user: User; private constants: any; public repositories: Repository[]; - public execution = new Excecution(); + public execution = new Execution(); public commands: Command[] = []; public client: Client; public cacheImages = []; @@ -102,9 +102,9 @@ export class DeleteCacheImageCommandComponent implements OnInit { this.execution.script += '\n'; } } - this.execution.script += this.constants.commands.REFRESH_INFO + '\n'; this.execution.script = this.execution.script.replace(/\"/g, '\\"').replace(/\$/g, '\\\$'); this.execution.type = 'RUN_SCRIPT'; + this.execution.sendConfig = true; this.commandService.execute(this.execution).subscribe( (response) => { diff --git a/admin/WebConsole3/frontend/src/app/pages/command/format-command/format-command.component.ts b/admin/WebConsole3/frontend/src/app/pages/command/format-command/format-command.component.ts index 62b733b8..05b3ebfe 100644 --- a/admin/WebConsole3/frontend/src/app/pages/command/format-command/format-command.component.ts +++ b/admin/WebConsole3/frontend/src/app/pages/command/format-command/format-command.component.ts @@ -11,6 +11,7 @@ import {OGCommandsService} from '../../../service/og-commands.service'; import {Client, Partition} from '../../../model/client'; import {CommandService} from '../../../api/command.service'; import {forkJoin} from 'rxjs'; +import {Execution} from '../../../model/command'; @Component({ selector: 'app-format-command', @@ -18,7 +19,7 @@ import {forkJoin} from 'rxjs'; styleUrls: [ './format-command.component.scss' ] }) export class FormatCommandComponent implements OnInit { - execution = {clients: '', script: '', type: ''}; + execution = new Execution(); command = {}; user: User; clientGroups = {}; @@ -85,10 +86,7 @@ export class FormatCommandComponent implements OnInit { const groups = Object.keys(this.clientGroups); for (let g = 0; g < groups.length; g++) { if (!executions[g]) { - executions[g] = { - clients: '', - script: '' - }; + executions[g] = new Execution(); } // Recorrer las particiones del primer cliente de la lista y ver si hay alguna seleccionada const found = false; @@ -101,7 +99,7 @@ export class FormatCommandComponent implements OnInit { while (!found && index < client.partitions.length) { const partition = client.partitions[index]; if (partition.selected === true) { - if(executions[g].script === '') { + if (executions[g].script === '') { executions[g].script = 'ogUnmountAll ' + partition.numDisk + '\n'; } // Si la particion es cache @@ -122,7 +120,8 @@ export class FormatCommandComponent implements OnInit { const execution = { type: 'RUN_SCRIPT', script: executions[index].script, - clients: executions[index].clients.substring(0, executions[index].clients.length - 1) // Quitar la ultima "," + clients: executions[index].clients.substring(0, executions[index].clients.length - 1), // Quitar la ultima "," + sendConfig: true }; promises.push(this.commandService.execute(execution)); } diff --git a/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.scss b/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.scss index 97d2231d..ec120f1f 100644 --- a/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.scss +++ b/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.scss @@ -12,11 +12,13 @@ right: 0; margin: 0; background-color: black; - width: 2px; + width: 4px; height: 100%; padding: 0 !important; cursor: col-resize; border: 1px solid transparent; } - + table.disk-partitions td:last-child span.resizer:last-child { + display: none; + } } diff --git a/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.ts b/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.ts index 8c75fa2e..eb36930a 100644 --- a/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.ts +++ b/admin/WebConsole3/frontend/src/app/pages/command/partition-format-command/partition-format-command.component.ts @@ -12,6 +12,7 @@ import {CommandService} from '../../../api/command.service'; import {DomSanitizer} from '@angular/platform-browser'; import {ChartOptions} from 'chart.js'; import {Client} from '../../../model/client'; +import {Execution} from '../../../model/command'; @Component({ selector: 'app-partition-format-command', @@ -19,7 +20,7 @@ import {Client} from '../../../model/client'; styleUrls: [ './partition-format-command.component.scss' ] }) export class PartitionFormatCommandComponent implements OnInit { - execution = {clients: '', script: '', type: ''}; + execution = new Execution(); command = {}; user: User; constants: any; diff --git a/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.html b/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.html index 4cb0f6e5..0a9abe16 100644 --- a/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.html +++ b/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.html @@ -1 +1,83 @@ -<div>Html template for class SoftwareProfile</div>
\ No newline at end of file +<section class="content-header"> + <h1 translate="software"> + </h1> + <ol class="breadcrumb"> + <li><a href="#/app/dashboard"><i class="fa fa-dashboard"></i> {{'dashboard'|translate}}</a></li> + <li><a href="#/app/software"><i class="fa fa-server"></i> {{'software'|translate}}</a></li> + <li class="active" translate="software_profile"></li> + </ol> +</section> +<section fixed-toolboxbar class="toolboxbar"> + <div> + <div class="col-md-12"> + <div class="box-tools pull-right"> + <button class="btn btn-primary" translate="save" (click)="save(Form)"></button> + </div> + </div> + </div> +</section> +<section class="content"> + <div class="row"> + <div class="col-md-6"> + <div class="box box-primary"> + <div class="box-header with-border"> + <h3 *ngIf="!softwareProfile.id" class="box-title" translate="new_software_profile"></h3> + <h3 *ngIf="softwareProfile.id" class="box-title" translate="software_profile"></h3> + </div> + <div class="box-body"> + <form role="form" name="Form"> + <app-form-input [cols]="1" [model]="softwareProfile" [formType]="formType"></app-form-input> + </form> + </div> + <div class="box-footer"> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="box box-primary"> + <div class="box-header with-border"> + <h4 translate="software_profile_components"></h4> + <div class="input-group"> + <input type="text" name="q" class="form-control" placeholder="Search..." + [(ngModel)]="searchText"> + <span class="input-group-btn"> + <button type="button" name="search" id="search-btn" class="btn btn-flat"><i + class="fa fa-search"></i> + </button> + </span> + </div> + </div> + <div class="box-body"> + <table class="table table-hover"> + <tbody> + <tr> + <th translate="select"></th> + <th translate="description"></th> + <th translate="type"></th> + </tr> + <tr *ngFor="let softwareComponent of softwareComponents; let index = index" + class="(index%2 == 0)?'odd':'even'"> + <td> + <input icheck checkbox-class="icheckbox_square-blue" radio-class="iradio_square-blue" + type="checkbox" class="selection-checkbox" + [(ngModel)]="softwareComponent.$$selected" + (change)="ogCommonService.checkUnchekComponent(softwareProfile, softwareComponent)"/> + </td> + <td> + <span> + {{softwareComponent.description}} + </span> + </td> + <td> + <span> + {{softwareComponent.type ? softwareComponent.type.name : '-'}} + </span> + </td> + </tr> + </tbody> + </table> + </div> + </div> + </div> + </div> +</section> diff --git a/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.ts b/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.ts index bff05a1c..b34cfb77 100644 --- a/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.ts +++ b/admin/WebConsole3/frontend/src/app/pages/software-profile/software-profile.component.ts @@ -1,17 +1,100 @@ -import { Component } from '@angular/core';
-
-import { SoftwareProfileService } from 'src/app/api/software-profile.service';
-import { SoftwareProfile } from 'src/app/model/software-profile';
-
-@Component({
- selector: 'software-profile',
- templateUrl: './software-profile.component.html',
- styleUrls: [ './software-profile.component.scss' ]
-})
-export class SoftwareProfileComponent {
- // this tells the tabs component which Pages
- // should be each tab's root Page
- constructor(public softwareProfileService: SoftwareProfileService) {
- }
-
-}
+import {Component, OnInit} from '@angular/core'; + +import { SoftwareProfileService } from 'src/app/api/software-profile.service'; +import {ParamMap, ActivatedRoute, Router} from '@angular/router'; +import {SoftwareProfile} from '../../model/software-profile'; +import {ToasterService} from '../../service/toaster.service'; +import {SoftwareComponentService} from '../../api/software-component.service'; +import {SoftwareComponent} from '../../model/software-component'; +import {SoftwareProfileFormType} from '../../form-type/software-profile.form-type'; +import {OgCommonService} from '../../service/og-common.service'; + +@Component({ + selector: 'app-software-profile', + templateUrl: './software-profile.component.html', + styleUrls: [ './software-profile.component.scss' ] +}) +export class SoftwareProfileComponent implements OnInit { + public softwareProfile: SoftwareProfile = new SoftwareProfile(); + public softwareComponents: SoftwareComponent[]; + formType: any; + // this tells the tabs component which Pages + // should be each tab's root Page + constructor(public ogCommonService: OgCommonService, public softwareProfileService: SoftwareProfileService, + public softwareComponentsService: SoftwareComponentService, private routerCtrl: Router, + private router: ActivatedRoute, private toaster: ToasterService) { + this.formType = new SoftwareProfileFormType().getForm(); + } + + ngOnInit(): void { + this.softwareComponentsService.list().subscribe( + components => { + this.softwareComponents = components; + this.router.paramMap.subscribe( + (params: ParamMap) => { + if(params.get('id')) { + this.softwareProfileService.read(Number(params.get('id'))).subscribe( + data => { + this.softwareProfile = data; + const self = this; + // Seleccionar los componentes adecuados + this.softwareComponents.forEach(function(component, index, array) { + if ( self.softwareProfile.softwares.find((value) => value.id === component.id)) { + // @ts-ignore + component.$$selected = true; + } + }); + }, + error => { + this.toaster.pop({type: 'error', body: 'error_loading_software_profile', title: 'error'}); + } + ); + } else { + this.softwareProfile = new SoftwareProfile(); + } + } + ); + }, + error => { + this.toaster.pop({type: 'error', body: 'error_loading_software_components', title: 'error'}); + } + ); + + } + + save() { + this.softwareProfile.softwares = []; + const self = this; + this.softwareComponents.forEach(function(component, index, array) { + // @ts-ignore + if (component.$$selected === true) { + // @ts-ignore + self.softwareProfile.softwares.push(component.id); + } + }); + // Actualizar o guardar + let request; + if(this.softwareProfile.id !== 0){ + request = this.softwareProfileService.update(this.softwareProfile); + } + else{ + request = this.softwareProfileService.create(this.softwareProfile); + } + request.subscribe( + (response) => { + this.toaster.pop({type: 'success', title: 'success', body: 'successfully_saved'}); + this.routerCtrl.navigate(['/app/software']).then( + success => { + console.log(success); + }, + error => { + console.log(error); + } + ); + }, + (error) => { + this.toaster.pop({type: 'error', title: 'error', body: error}); + } + ); + } +} diff --git a/admin/WebConsole3/frontend/src/app/service/og-commands.service.ts b/admin/WebConsole3/frontend/src/app/service/og-commands.service.ts index 1ea33faa..6b54a896 100644 --- a/admin/WebConsole3/frontend/src/app/service/og-commands.service.ts +++ b/admin/WebConsole3/frontend/src/app/service/og-commands.service.ts @@ -39,9 +39,16 @@ export class OGCommandsService { this.commandService.execute(this.execution).subscribe( (response: any[]) => { // Buscar en la respuesta si hay algún statuscode diferente de 200 - const errors = response.filter(function(value) { - return (value.statusCode && value.statusCode !== '!200'); - } ); + const errors = []; + const keys = Object.keys(response); + keys.forEach((index) => { + const elemKeys = Object.keys(response[index]); + elemKeys.forEach((elemKey) => { + if (elemKey === 'statusCode' && response[index][elemKey] !== 200) { + errors.push(response[index]); + } + }); + }); let errorStr = ''; let toasterOpts = {type: 'success', title: 'success', body: this.translate.instant('successfully_executed')}; if (errors.length > 0) { @@ -116,7 +123,7 @@ export class OGCommandsService { // Crear como nombre para mostrar, el disco y partición del sistema const obj = Object.assign({}, client.partitions[index]); const str = 'disco: ' + obj.numDisk + ', part: ' + obj.numPartition + ', SO: ' + client.partitions[index].osName; - clonablePartitions.push(obj.numDisk + ' ' + obj.numPartition) + clonablePartitions.push(obj.numDisk + ' ' + obj.numPartition); options.scope.partitions.push(str); } } diff --git a/admin/WebConsole3/frontend/src/app/service/og-common.service.ts b/admin/WebConsole3/frontend/src/app/service/og-common.service.ts index b529199d..3de25304 100644 --- a/admin/WebConsole3/frontend/src/app/service/og-common.service.ts +++ b/admin/WebConsole3/frontend/src/app/service/og-common.service.ts @@ -198,15 +198,13 @@ export class OgCommonService { } saveSelection() { - if (Object.keys(this.selectedClients).length > 0) { - localStorage.setItem('selectedClients', JSON.stringify(this.selectedClients, function (key, value) { - let result = value; - if (key === 'parent' && typeof value === 'object') { - result = value.id; - } - return result; - })); - } + localStorage.setItem('selectedClients', JSON.stringify(this.selectedClients, function (key, value) { + let result = value; + if (key === 'parent' && typeof value === 'object') { + result = value.id; + } + return result; + })); } getSelectionSize() { |