refs #1740. Run assistant updates. Save command
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
parent
1c417e5f35
commit
4f2bf0ec05
|
@ -138,6 +138,9 @@ import { ShowImagesComponent } from './components/repositories/show-images/show-
|
|||
import { StatusTabComponent } from './components/global-status/status-tab/status-tab.component';
|
||||
import { ConvertImageToVirtualComponent } from './components/repositories/convert-image-to-virtual/convert-image-to-virtual.component';
|
||||
import { RunScriptAssistantComponent } from './components/groups/components/client-main-view/run-script-assistant/run-script-assistant.component';
|
||||
import {
|
||||
SaveScriptComponent
|
||||
} from "./components/groups/components/client-main-view/run-script-assistant/save-script/save-script.component";
|
||||
|
||||
export function HttpLoaderFactory(http: HttpClient) {
|
||||
return new TranslateHttpLoader(http, './locale/', '.json');
|
||||
|
@ -235,7 +238,8 @@ registerLocaleData(localeEs, 'es-ES');
|
|||
ShowImagesComponent,
|
||||
StatusTabComponent,
|
||||
ConvertImageToVirtualComponent,
|
||||
RunScriptAssistantComponent
|
||||
RunScriptAssistantComponent,
|
||||
SaveScriptComponent
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
imports: [BrowserModule,
|
||||
|
|
|
@ -22,14 +22,14 @@ export class ExecuteCommandComponent implements OnInit {
|
|||
{ name: 'Enceder', slug: 'power-on', disabled: false },
|
||||
{ name: 'Apagar', slug: 'power-off', disabled: false },
|
||||
{ name: 'Reiniciar', slug: 'reboot', disabled: false },
|
||||
{ name: 'Iniciar Sesión', slug: 'login', disabled: false },
|
||||
{ name: 'Iniciar Sesión', slug: 'login', disabled: true },
|
||||
{ name: 'Crear imagen', slug: 'create-image', disabled: false },
|
||||
{ name: 'Clonar/desplegar imagen', slug: 'deploy-image', disabled: false },
|
||||
{ name: 'Eliminar Imagen Cache', slug: 'delete-image-cache', disabled: true },
|
||||
{ name: 'Particionar y Formatear', slug: 'partition', disabled: false },
|
||||
{ name: 'Inventario Software', slug: 'software-inventory', disabled: true },
|
||||
{ name: 'Inventario Hardware', slug: 'hardware-inventory', disabled: true },
|
||||
{ name: 'Ejecutar script', slug: 'run-script', disabled: false },
|
||||
{ name: 'Ejecutar comando', slug: 'run-script', disabled: false },
|
||||
];
|
||||
|
||||
client: any = {};
|
||||
|
|
|
@ -48,7 +48,7 @@ export class ClientMainViewComponent implements OnInit {
|
|||
{ name: 'Particionar y Formatear', slug: 'partition' },
|
||||
{ name: 'Inventario Software', slug: 'software-inventory' },
|
||||
{ name: 'Inventario Hardware', slug: 'hardware-inventory' },
|
||||
{ name: 'Ejecutar script', slug: 'run-script' },
|
||||
{ name: 'Ejecutar comando', slug: 'run-script' },
|
||||
];
|
||||
|
||||
datePipe: DatePipe = new DatePipe('es-ES');
|
||||
|
|
|
@ -134,11 +134,15 @@ table {
|
|||
}
|
||||
|
||||
.client-name {
|
||||
display: block;
|
||||
font-size: 1.2em;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 150px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.client-ip {
|
||||
|
@ -178,3 +182,13 @@ table {
|
|||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.mat-expansion-panel-header-description {
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
|
|
@ -13,18 +13,22 @@
|
|||
<mat-divider></mat-divider>
|
||||
|
||||
<div class="select-container">
|
||||
<mat-expansion-panel hideToggle>
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title> Clientes </mat-panel-title>
|
||||
<mat-panel-description> Listado de clientes donde se desplegará la imagen </mat-panel-description>
|
||||
<mat-panel-description>
|
||||
Listado de clientes donde se desplegará la imagen
|
||||
<mat-icon>desktop_windows</mat-icon>
|
||||
</mat-panel-description>
|
||||
</mat-expansion-panel-header>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div class="button-row">
|
||||
<button class="action-button" (click)="toggleSelectAll()">
|
||||
{{ allSelected ? 'Desmarcar' : 'Marcar' }}
|
||||
{{ allSelected ? 'Desmarcar todos' : 'Marcar todos' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div *ngFor="let client of clientData" class="client-item">
|
||||
<div class="client-card"
|
||||
(click)="client.status === 'og-live' && toggleClientSelection(client)"
|
||||
|
@ -39,17 +43,18 @@
|
|||
class="client-image" />
|
||||
|
||||
<div class="client-details">
|
||||
<span class="client-name">{{ client.name }}</span>
|
||||
<span class="client-name">{{ client.name | slice:0:20 }}</span>
|
||||
<span class="client-ip">{{ client.ip }}</span>
|
||||
<span class="client-ip">{{ client.mac }}</span>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
|
||||
<mat-radio-group [(ngModel)]="selectedModelClient" (change)="loadPartitions(selectedModelClient)">
|
||||
<mat-radio-button [value]="client"
|
||||
color="primary"
|
||||
[disabled]="!client.selected"
|
||||
(click)="$event.stopPropagation()">
|
||||
Particiones
|
||||
Modelo
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
|
|
|
@ -114,7 +114,10 @@ export class DeployImageComponent {
|
|||
(client: { status: string }) => client.status === 'og-live'
|
||||
);
|
||||
|
||||
this.selectedModelClient = this.clientData[0];
|
||||
this.selectedModelClient = this.clientData.find(
|
||||
(client: { status: string }) => client.status === 'og-live'
|
||||
) || null;
|
||||
|
||||
if (this.selectedModelClient) {
|
||||
this.loadPartitions(this.selectedModelClient);
|
||||
}
|
||||
|
|
|
@ -157,11 +157,15 @@ button.remove-btn:hover {
|
|||
}
|
||||
|
||||
.client-name {
|
||||
display: block;
|
||||
font-size: 1.2em;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 150px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.client-ip {
|
||||
|
@ -232,5 +236,16 @@ button.remove-btn:hover {
|
|||
}
|
||||
|
||||
|
||||
.action-button {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.mat-expansion-panel-header-description {
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,18 +12,22 @@
|
|||
</div>
|
||||
|
||||
<div class="select-container">
|
||||
<mat-expansion-panel hideToggle>
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title> Clientes </mat-panel-title>
|
||||
<mat-panel-description> Listado de clientes donde se realizará el particionado </mat-panel-description>
|
||||
<mat-panel-description>
|
||||
Listado de clientes donde se realizará el particionado
|
||||
<mat-icon>desktop_windows</mat-icon>
|
||||
</mat-panel-description>
|
||||
</mat-expansion-panel-header>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div class="button-row">
|
||||
<button class="action-button" (click)="toggleSelectAll()">
|
||||
{{ allSelected ? 'Desmarcar' : 'Marcar' }}
|
||||
{{ allSelected ? 'Desmarcar todos' : 'Marcar todos' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div *ngFor="let client of clientData" class="client-item">
|
||||
<div class="client-card"
|
||||
(click)="client.status === 'og-live' && toggleClientSelection(client)"
|
||||
|
@ -42,12 +46,13 @@
|
|||
<span class="client-ip">{{ client.ip }}</span>
|
||||
<span class="client-ip">{{ client.mac }}</span>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
<mat-radio-group [(ngModel)]="selectedModelClient" (change)="loadPartitions(selectedModelClient)">
|
||||
<mat-radio-button [value]="client"
|
||||
color="primary"
|
||||
[disabled]="!client.selected"
|
||||
(click)="$event.stopPropagation()">
|
||||
Particiones
|
||||
Modelo
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
|
||||
|
|
|
@ -69,8 +69,14 @@ export class PartitionAssistantComponent {
|
|||
client.selected = true;
|
||||
}
|
||||
});
|
||||
this.selectedClients = [...this.clientData];
|
||||
this.selectedModelClient = this.clientData[0];
|
||||
|
||||
this.selectedClients = this.clientData.filter(
|
||||
(client: { status: string }) => client.status === 'og-live'
|
||||
);
|
||||
|
||||
this.selectedModelClient = this.clientData.find(
|
||||
(client: { status: string }) => client.status === 'og-live'
|
||||
) || null;
|
||||
this.loadPartitions(this.selectedModelClient);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,8 @@ table {
|
|||
min-height: 50px;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
.custom-width {
|
||||
width: 50%;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
|
@ -148,11 +148,15 @@ table {
|
|||
}
|
||||
|
||||
.client-name {
|
||||
display: block;
|
||||
font-size: 1.2em;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 150px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.client-ip {
|
||||
|
@ -212,3 +216,45 @@ table {
|
|||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.mat-expansion-panel-header-description {
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.new-command-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 15px;
|
||||
background-color: #eaeff6;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.new-command-container mat-form-field {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.new-command-container textarea {
|
||||
font-family: monospace;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.new-command-container .action-button {
|
||||
align-self: flex-end;
|
||||
color: white;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,24 +7,28 @@
|
|||
</h2>
|
||||
</div>
|
||||
<div class="button-row">
|
||||
<button class="action-button" [disabled]="!selectedScript" (click)="save()">Ejecutar</button>
|
||||
<button class="action-button" [disabled]="selectedClients.length < 1 || (commandType === 'existing' && !selectedScript)" (click)="save()">Ejecutar</button>
|
||||
</div>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
|
||||
<div class="select-container">
|
||||
<mat-expansion-panel hideToggle>
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title> Clientes </mat-panel-title>
|
||||
<mat-panel-description> Listado de clientes donde se ejectutará el script </mat-panel-description>
|
||||
<mat-panel-description>
|
||||
Listado de clientes donde se ejecutara el script seleccionado
|
||||
<mat-icon>desktop_windows</mat-icon>
|
||||
</mat-panel-description>
|
||||
</mat-expansion-panel-header>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div class="button-row">
|
||||
<button class="action-button" (click)="toggleSelectAll()">
|
||||
{{ allSelected ? 'Desmarcar' : 'Marcar' }}
|
||||
{{ allSelected ? 'Desmarcar todos' : 'Marcar todos' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="clients-grid">
|
||||
<div *ngFor="let client of clientData" class="client-item">
|
||||
<div class="client-card"
|
||||
(click)="client.status === 'og-live' && toggleClientSelection(client)"
|
||||
|
@ -52,22 +56,38 @@
|
|||
<mat-divider style="margin-top: 20px;"></mat-divider>
|
||||
|
||||
<div class="select-container">
|
||||
<div class="deploy-container">
|
||||
<div class="command-toggle">
|
||||
<mat-radio-group [(ngModel)]="commandType">
|
||||
<mat-radio-button value="new">Comando nuevo</mat-radio-button>
|
||||
<mat-radio-button value="existing">Comando existente</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
|
||||
<div *ngIf="commandType === 'new'" class="new-command-container">
|
||||
<mat-form-field appearance="fill" class="full-width">
|
||||
<mat-label>Ingrese el script</mat-label>
|
||||
<textarea matInput [(ngModel)]="newScript" rows="6" placeholder="Escriba su script aquí"></textarea>
|
||||
</mat-form-field>
|
||||
<button class="action-button" (click)="saveNewScript()">Guardar Comando</button>
|
||||
</div>
|
||||
|
||||
<div *ngIf="commandType === 'existing'" class="select-container">
|
||||
<mat-form-field appearance="fill" class="custom-width">
|
||||
<mat-label>Seleccione script a ejecutar</mat-label>
|
||||
<mat-select [(ngModel)]="selectedScript" (selectionChange)="onScriptChange()">
|
||||
<mat-option *ngFor="let script of scripts" [value]="script">{{ script.name }}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div *ngIf="selectedScript" class="script-container">
|
||||
<div *ngIf="selectedScript" class="script-content">
|
||||
|
||||
<div *ngIf="selectedScript && commandType === 'existing'" class="script-container">
|
||||
<div class="script-content">
|
||||
<h3> Script:</h3>
|
||||
<div class="script-preview" [innerHTML]="scriptContent"></div>
|
||||
</div>
|
||||
|
||||
<div class="script-params" *ngIf="parameters.length > 0">
|
||||
<h3>Ingrese los valores de los parámetros:</h3>
|
||||
<h3>Ingrese los valores de los parámetros detectados:</h3>
|
||||
<div *ngFor="let param of parameters; let i = index">
|
||||
<mat-form-field appearance="fill" class="full-width">
|
||||
<mat-label>Parámetro {{ i + 1 }}</mat-label>
|
||||
|
|
|
@ -25,6 +25,7 @@ import { HttpClient } from '@angular/common/http';
|
|||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import {MatIconModule} from "@angular/material/icon";
|
||||
|
||||
export function HttpLoaderFactory(http: HttpClient) {
|
||||
return new TranslateHttpLoader(http);
|
||||
|
@ -57,6 +58,7 @@ describe('RunScriptAssistantComponent', () => {
|
|||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
BrowserAnimationsModule,
|
||||
MatIconModule,
|
||||
ToastrModule.forRoot(),
|
||||
HttpClientTestingModule,
|
||||
TranslateModule.forRoot({
|
||||
|
|
|
@ -4,6 +4,8 @@ import {HttpClient} from "@angular/common/http";
|
|||
import {ToastrService} from "ngx-toastr";
|
||||
import {ConfigService} from "@services/config.service";
|
||||
import {ActivatedRoute, Router} from "@angular/router";
|
||||
import {SaveScriptComponent} from "./save-script/save-script.component";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
|
||||
@Component({
|
||||
selector: 'app-run-script-assistant',
|
||||
|
@ -26,6 +28,8 @@ export class RunScriptAssistantComponent {
|
|||
selectedScript: any = null;
|
||||
selectedClients: any[] = [];
|
||||
allSelected: boolean = true;
|
||||
commandType: string = 'existing';
|
||||
newScript: string = '';
|
||||
selection = new SelectionModel(true, []);
|
||||
|
||||
constructor(
|
||||
|
@ -33,6 +37,7 @@ export class RunScriptAssistantComponent {
|
|||
private toastService: ToastrService,
|
||||
private configService: ConfigService,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private route: ActivatedRoute
|
||||
) {
|
||||
this.baseUrl = this.configService.apiUrl;
|
||||
|
@ -65,6 +70,23 @@ export class RunScriptAssistantComponent {
|
|||
});
|
||||
}
|
||||
|
||||
saveNewScript() {
|
||||
if (!this.newScript.trim()) {
|
||||
this.toastService.error('Debe ingresar un script antes de guardar.');
|
||||
return;
|
||||
}
|
||||
const dialogRef = this.dialog.open(SaveScriptComponent, {
|
||||
width: '400px',
|
||||
data: this.newScript
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (result) {
|
||||
this.toastService.success('Script guardado correctamente');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleClientSelection(client: any) {
|
||||
client.selected = !client.selected;
|
||||
this.updateSelectedClients();
|
||||
|
@ -119,11 +141,12 @@ export class RunScriptAssistantComponent {
|
|||
|
||||
this.http.post(`${this.baseUrl}/commands/run-script`, {
|
||||
clients: this.selectedClients.map((client: any) => client.uuid),
|
||||
script: this.scriptContent
|
||||
script: this.commandType === 'existing' ? this.scriptContent : this.newScript,
|
||||
}).subscribe(
|
||||
response => {
|
||||
this.toastService.success('Script ejecutado correctamente');
|
||||
this.dataChange.emit();
|
||||
this.router.navigate(['/commands-logs']);
|
||||
},
|
||||
error => {
|
||||
this.toastService.error('Error al ejecutar el script');
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
.dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.repository-form {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.full-width{
|
||||
width: 100%;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.action-container {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 1em;
|
||||
padding: 1.5em;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.form-field {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<h2 mat-dialog-title>Guardar Comando</h2>
|
||||
<mat-dialog-content>
|
||||
<p>Introduce un nombre para el comando:</p>
|
||||
<mat-form-field appearance="fill" class="full-width">
|
||||
<mat-label>Nombre del Comando</mat-label>
|
||||
<input matInput [(ngModel)]="commandName">
|
||||
</mat-form-field>
|
||||
</mat-dialog-content>
|
||||
<div mat-dialog-actions class="action-container">
|
||||
<button class="ordinary-button" (click)="close()">Cancelar</button>
|
||||
<button class="submit-button" (click)="save()">Guardar</button>
|
||||
</div>
|
|
@ -0,0 +1,94 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {RunScriptAssistantComponent} from "../run-script-assistant.component";
|
||||
import {DeployImageComponent} from "../../deploy-image/deploy-image.component";
|
||||
import {LoadingComponent} from "../../../../../../shared/loading/loading.component";
|
||||
import {FormBuilder, FormsModule, ReactiveFormsModule} from "@angular/forms";
|
||||
import {MAT_DIALOG_DATA, MatDialogModule, MatDialogRef} from "@angular/material/dialog";
|
||||
import {MatFormFieldModule} from "@angular/material/form-field";
|
||||
import {MatInputModule} from "@angular/material/input";
|
||||
import {MatCheckboxModule} from "@angular/material/checkbox";
|
||||
import {MatExpansionModule} from "@angular/material/expansion";
|
||||
import {MatButtonModule} from "@angular/material/button";
|
||||
import {MatTableModule} from "@angular/material/table";
|
||||
import {MatDividerModule} from "@angular/material/divider";
|
||||
import {MatRadioModule} from "@angular/material/radio";
|
||||
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||
import {MatSelectModule} from "@angular/material/select";
|
||||
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
||||
import {MatIconModule} from "@angular/material/icon";
|
||||
import {ToastrModule, ToastrService} from "ngx-toastr";
|
||||
import {HttpClientTestingModule, provideHttpClientTesting} from "@angular/common/http/testing";
|
||||
import {TranslateLoader, TranslateModule} from "@ngx-translate/core";
|
||||
import {HttpClient, provideHttpClient} from "@angular/common/http";
|
||||
import {provideRouter} from "@angular/router";
|
||||
import {ConfigService} from "@services/config.service";
|
||||
import {HttpLoaderFactory} from "../run-script-assistant.component.spec";
|
||||
import {SaveScriptComponent} from "./save-script.component";
|
||||
|
||||
describe('SaveScriptComponent', () => {
|
||||
let component: SaveScriptComponent;
|
||||
let fixture: ComponentFixture<SaveScriptComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const mockConfigService = {
|
||||
apiUrl: 'http://mock-api-url',
|
||||
mercureUrl: 'http://mock-mercure-url'
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [RunScriptAssistantComponent, DeployImageComponent, LoadingComponent],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatCheckboxModule,
|
||||
MatExpansionModule,
|
||||
MatButtonModule,
|
||||
MatTableModule,
|
||||
MatDividerModule,
|
||||
MatRadioModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
BrowserAnimationsModule,
|
||||
MatIconModule,
|
||||
ToastrModule.forRoot(),
|
||||
HttpClientTestingModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useFactory: HttpLoaderFactory,
|
||||
deps: [HttpClient]
|
||||
}
|
||||
})
|
||||
],
|
||||
providers: [
|
||||
FormBuilder,
|
||||
ToastrService,
|
||||
provideHttpClient(),
|
||||
provideHttpClientTesting(),
|
||||
provideRouter([]),
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {}
|
||||
},
|
||||
{
|
||||
provide: MAT_DIALOG_DATA,
|
||||
useValue: {}
|
||||
},
|
||||
{ provide: ConfigService, useValue: mockConfigService }
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SaveScriptComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
import {Component, Inject} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {FormBuilder, Validators} from "@angular/forms";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {ToastrService} from "ngx-toastr";
|
||||
import {ConfigService} from "@services/config.service";
|
||||
import {DataService} from "../../../../../commands/main-commands/data.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-save-script',
|
||||
templateUrl: './save-script.component.html',
|
||||
styleUrl: './save-script.component.css'
|
||||
})
|
||||
export class SaveScriptComponent {
|
||||
commandName: string = '';
|
||||
baseUrl: string;
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
public dialogRef: MatDialogRef<SaveScriptComponent>,
|
||||
private toastService: ToastrService,
|
||||
private configService: ConfigService,
|
||||
private dataService: DataService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) {
|
||||
this.baseUrl = this.configService.apiUrl;
|
||||
}
|
||||
|
||||
save() {
|
||||
const payload = {
|
||||
name: this.commandName,
|
||||
script: this.data,
|
||||
readOnly: false,
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
this.http.post(`${this.baseUrl}/commands`, payload).subscribe(
|
||||
(response) => {
|
||||
this.toastService.success('Comando añadido correctamente');
|
||||
this.dialogRef.close();
|
||||
},
|
||||
(error) => {
|
||||
this.toastService.error(error['error']['hydra:description']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
close() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@
|
|||
"statusAvailable": "Disponible",
|
||||
"parameters": "Parámetros",
|
||||
"labelRoleName": "Nombre",
|
||||
"runScript": "Ejecutar script",
|
||||
"runScript": "Ejecutar comando",
|
||||
"sectionTitlePermissions": "Permisos:",
|
||||
"checkboxSuperAdmin": "Super Admin",
|
||||
"checkboxOrgAdmin": "Admin de Unidad Organizativa",
|
||||
|
|
Loading…
Reference in New Issue