Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Stoffel committed Nov 29, 2023
2 parents b5ce878 + 58e1fdb commit 19a494c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
4 changes: 2 additions & 2 deletions analytics-ui/src/analytics-extension.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { BlockGridComponent } from "./analytics/list/block.component";
import { AnalyticsAddExtensionComponent } from "./analytics/manage/extension-add.component";
import { SampleGridComponent } from "./sample/list/sample.component";
import { HttpClientModule } from "@angular/common/http";
import { NameExtensionComponent } from "./wizard/name-extension-modal.component";
import { CreateExtensionComponent } from "./wizard/create-extension-modal.component";
import { EditorStepperComponent } from "./sample/editor/editor-stepper.component";
import { EditorModalComponent } from "./sample/editor/editor-modal.component";
import { RepositoriesModalComponent } from "./sample/editor/repositories-modal.component";
Expand Down Expand Up @@ -60,7 +60,7 @@ const routes: Route[] = [
AnalyticsExtensionCardComponent,
AnalyticsAddExtensionComponent,
AddExtensionWizardComponent,
NameExtensionComponent,
CreateExtensionComponent,
BlockGridComponent,
SampleGridComponent,
EditorStepperComponent,
Expand Down
5 changes: 3 additions & 2 deletions analytics-ui/src/sample/list/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { AnalyticsService } from "../../shared/analytics.service";
import { CEP_Block } from "../../shared/analytics.model";
import { BsModalService } from "ngx-bootstrap/modal";
import { NameExtensionComponent } from "../../wizard/name-extension-modal.component";
import { CreateExtensionComponent } from "../../wizard/create-extension-modal.component";
import { EditorModalComponent } from "../editor/editor-modal.component";
import { RepositoriesModalComponent } from "../editor/repositories-modal.component";
import { RepositoryService } from "../editor/repository.service";
Expand Down Expand Up @@ -175,7 +175,8 @@ export class SampleGridComponent implements OnInit {
monitors
};

const modalRef = this.bsModalService.show(NameExtensionComponent, {
const modalRef = this.bsModalService.show(CreateExtensionComponent, {
class: "modal-lg",
initialState,
});

Expand Down
3 changes: 2 additions & 1 deletion analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class AnalyticsService {

async createExtensionsZIP(
name: string,
upload: boolean,
monitors: string[]
): Promise<IFetchResponse> {
console.log(`Create extensions for : ${name}, ${monitors},`);
Expand All @@ -90,8 +91,8 @@ export class AnalyticsService {
},
body: JSON.stringify({
extension_name: name,
upload: upload,
monitors: monitors,
upload: false,
}),
method: "POST",
responseType: "blob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ import { saveAs } from "file-saver";
[fields]="configFormlyFields"
[model]="configuration"
></formly-form>
<div class="col-lg-8">
<button
class="btn btn-default"
title="{{ 'Create Extension' | translate }}"
(click)="createExtension()"
>
<i c8yIcon="plugin"></i>
{{ "Create Extension" | translate }}
</button>
</div>
</div>
<button
class="btn btn-default"
title="{{ 'Create Extension' | translate }}"
(click)="createExtension()"
>
<i c8yIcon="plugin"></i>
{{ "Create Extension" | translate }}
</button>
</div>
<div *ngIf="loading"><c8y-loading></c8y-loading></div>
</c8y-modal>`,
})
export class NameExtensionComponent implements OnInit {
export class CreateExtensionComponent implements OnInit {
@Output() closeSubject: Subject<any> = new Subject();
@Input() monitors: string[];
configuration: any = {};
Expand All @@ -51,14 +53,30 @@ export class NameExtensionComponent implements OnInit {
ngOnInit(): void {
this.configFormlyFields = [
{
className: "col-lg-12",
key: "name",
type: "input",
wrappers: ["c8y-form-field"],
templateOptions: {
label: "Name Extension",
required: true,
},
fieldGroup: [
{
className: "col-lg-8",
key: "name",
type: "input",
wrappers: ["c8y-form-field"],
templateOptions: {
label: "Name Extension",
required: true,
},
},
{
className: "col-lg-4",
key: "upload",
type: "switch",
defaultValue: false,
wrappers: ["c8y-form-field"],
templateOptions: {
label: "Upload Extension",
description:
"The generated extension for the selected blocks is uploaded. After initiating a restart they are available in the Analytics Builder model pallet.",
},
},
],
},
];
}
Expand All @@ -73,6 +91,7 @@ export class NameExtensionComponent implements OnInit {
console.log("Create Extension");
const response = await this.analyticsService.createExtensionsZIP(
this.configuration.name,
this.configuration.upload,
this.monitors
);
const binary = await await response.arrayBuffer();
Expand All @@ -81,7 +100,9 @@ export class NameExtensionComponent implements OnInit {
type: "application/x-zip-compressed",
});
saveAs(blob, `${this.configuration.name}.zip`);
this.alertService.success(`Created extension ${this.configuration.name}.zip!`)
this.alertService.success(
`Created extension ${this.configuration.name}.zip!`
);
this.closeSubject.next(true);
}
}

0 comments on commit 19a494c

Please sign in to comment.