diff options
Diffstat (limited to 'admin/WebConsole3/frontend/src/app/pages/software-profile')
2 files changed, 183 insertions, 18 deletions
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}); + } + ); + } +} |