Skip to content

Commit

Permalink
added dialog to name extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 24, 2023
1 parent 7c328d9 commit cb54caf
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 8 deletions.
10 changes: 6 additions & 4 deletions analytics-ui/src/analytics-extension.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { BinaryFileDownloadModule } from "@c8y/ngx-components/binary-file-download";
import { DefaultSubscriptionsModule } from "@c8y/ngx-components/default-subscriptions";
import { BsDropdownModule } from "ngx-bootstrap/dropdown";
import { AnalyticsExtensionWizardComponent } from "./wizard/analytics-extension-wizard.component";
import { AddExtensionWizardComponent } from "./wizard/add-extension-wizard.component";
import { AnalyticsExtensionCardComponent } from "./analytics/manage/extension-card.component";
import { AnalyticsExtensionComponent } from "./analytics/manage/extension.component";
import { AnalyticsService } from "./shared/analytics.service";
Expand All @@ -22,6 +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";

const routes: Route[] = [
{
Expand Down Expand Up @@ -54,15 +55,16 @@ const routes: Route[] = [
AnalyticsExtensionComponent,
AnalyticsExtensionCardComponent,
AnalyticsAddExtensionComponent,
AnalyticsExtensionWizardComponent,
AddExtensionWizardComponent,
NameExtensionComponent,
BlockGridComponent,
SampleGridComponent,
],
entryComponents: [
AnalyticsExtensionComponent,
AnalyticsExtensionCardComponent,
AnalyticsAddExtensionComponent,
AnalyticsExtensionWizardComponent,
AnalyticsExtensionCardComponent,
BlockGridComponent,
SampleGridComponent,
],
Expand All @@ -71,7 +73,7 @@ const routes: Route[] = [
hookNavigator(AnalyticsNavigationFactory),
hookWizard({
wizardId: "uploadAnalyticsExtention",
component: AnalyticsExtensionWizardComponent,
component: AnalyticsExtensionCardComponent,
name: "Upload analytics extension",
c8yIcon: "upload",
}),
Expand Down
1 change: 1 addition & 0 deletions analytics-ui/src/sample/list/sample.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
[pagination]="pagination"
[selectable]="'true'"
[actionControls]="actionControls"
[bulkActionControls]="bulkActionControls"
>
</c8y-data-grid>
</div>
Expand Down
49 changes: 46 additions & 3 deletions analytics-ui/src/sample/list/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ import {
import {
ActionControl,
AlertService,
BulkActionControl,
Column,
ColumnDataType,
Pagination,
gettext,
} from "@c8y/ngx-components";
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";

@Component({
selector: "c8y-sample-grid",
Expand All @@ -44,8 +48,9 @@ export class SampleGridComponent implements OnInit {
showConfigSample: boolean = false;
refresh: EventEmitter<any> = new EventEmitter<any>();

samples: Partial<CEP_Block>[] = [];
samples: any[] = [];
actionControls: ActionControl[] = [];
bulkActionControls: BulkActionControl[] = [];

titleSample: string = "AnalyticsBuilder Community Samples";

Expand All @@ -54,7 +59,13 @@ export class SampleGridComponent implements OnInit {
name: "name",
header: "Name",
path: "name",
filterable: false,
dataType: ColumnDataType.TextLong,
visible: true,
},
{
name: "url",
header: "URL",
path: "url",
dataType: ColumnDataType.TextLong,
visible: true,
},
Expand All @@ -67,14 +78,46 @@ export class SampleGridComponent implements OnInit {

constructor(
public analyticsService: AnalyticsService,
public alertService: AlertService
public alertService: AlertService,
private bsModalService: BsModalService,
) {}

async ngOnInit() {
await this.loadSamples();
this.refresh.subscribe(() => {
this.loadSamples();
});

this.bulkActionControls.push(
{
type: "CREATE",
text: "Create Extension",
icon: "export",
callback: this.createExtension.bind(this),
},
);
}

public async createExtension(ids: string[]) {

const initialState = {};
const modalRef = this.bsModalService.show(NameExtensionComponent, {
initialState,
});
modalRef.content.closeSubject.subscribe(async (conf) => {
console.log("Configuration after edit:", conf);
if (conf) {
const response =
await this.analyticsService.createExtensionsZIP(conf.name, ids);
if (response) {
this.alertService.success(gettext(`Created extension ${conf.name}.zip successfully‚`));
} else {
this.alertService.danger(
gettext("Failed to create extension")
);
}
}
});
}

async loadSamples() {
Expand Down
8 changes: 8 additions & 0 deletions analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export class AnalyticsService {
}
return result;
}


async createExtensionsZIP(name: string, monitors: string[]): Promise<any> {
const result = {};
return result;
}

async getWebExtensions(customFilter: any = {}): Promise<IManagedObject[]> {
return (await this.getExtensions(customFilter)).data;
}
Expand Down Expand Up @@ -138,6 +145,7 @@ export class AnalyticsService {
.pipe(
map((data) => {
const name = _.values(data);
name.forEach( b => b.id = b.sha)
return name ;
}),
).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AnalyticsService } from '../shared/analytics.service';
[canGoBack]="true"
></extension-add>`
})
export class AnalyticsExtensionWizardComponent {
export class AddExtensionWizardComponent {
headerText: string = gettext('Upload analytics extension');
successText: string = gettext('Extension created');

Expand Down
60 changes: 60 additions & 0 deletions analytics-ui/src/wizard/name-extension-modal.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Component, Input, OnInit, Output } from "@angular/core";
import { ModalLabels } from "@c8y/ngx-components";
import { Subject } from "rxjs";
import { FormlyFieldConfig } from "@ngx-formly/core";
import { FormGroup } from "@angular/forms";

@Component({
selector: "name-extension-modal",
template: `<c8y-modal
title="Edit properties extension"
(onClose)="onSave($event)"
(onDismiss)="onDismiss($event)"
[labels]="labels"
[headerClasses]="'modal-header dialog-header'"
>
<div class="card-block">
<div [formGroup]="configFormly">
<formly-form
[form]="configFormly"
[fields]="configFormlyFields"
[model]="configuration"
></formly-form>
</div>
</div>
</c8y-modal>`,
})
export class NameExtensionComponent implements OnInit {
@Output() closeSubject: Subject<any> = new Subject();
configuration: any = {};

configFormlyFields: FormlyFieldConfig[] = [];
configFormly: FormGroup = new FormGroup({});
labels: ModalLabels = { ok: "Save", cancel: "Dismiss" };

ngOnInit(): void {
this.configFormlyFields = [
{
className: "col-lg-12",
key: "name",
type: "input",
wrappers: ["c8y-form-field"],
templateOptions: {
label: "Name Extension",
required: true,
},
},
];
}

onDismiss(event) {
console.log("Dismiss");
this.closeSubject.next(undefined);
}

onSave(event) {
console.log("Save");
this.closeSubject.next(this.configuration);
}

}

0 comments on commit cb54caf

Please sign in to comment.