Skip to content

Commit

Permalink
#16: moves asset selection to formly field (#25)
Browse files Browse the repository at this point in the history
* #16: moves asset selection to formly field

* #16: removes dev logging

---------

Co-authored-by: Dirk Peter <[email protected]>
  • Loading branch information
dirk-peter-c8y and Dirk Peter authored Jun 12, 2024
1 parent b4fb982 commit abb56cd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 49 deletions.
14 changes: 14 additions & 0 deletions plugin/components/asset.formly/asset.formly.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<c8y-asset-selector-miller
class="m-b-24"
[selectedDevice]="field.props.asset"
[config]="{
groupsSelectable: true,
singleColumn: true,
columnHeaders: true,
showFilter: true,
search: true,
label: field.props.label
}"
[formControl]="formControl"
[formlyAttributes]="field">
</c8y-asset-selector-miller>
6 changes: 6 additions & 0 deletions plugin/components/asset.formly/asset.formly.component.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:host ::ng-deep {
.miller-column__selection {
padding-left: 0 !important;
padding-right: 0 !important;
}
}
9 changes: 9 additions & 0 deletions plugin/components/asset.formly/asset.formly.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '@angular/core';
import { FieldType, FieldTypeConfig } from '@ngx-formly/core';

@Component({
selector: 'formly-asset',
templateUrl: './asset.formly.component.html',
styleUrls: ['./asset.formly.component.less']
})
export class AssetFieldType extends FieldType<FieldTypeConfig> {}
15 changes: 0 additions & 15 deletions plugin/components/reminder-modal/reminder-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,9 @@ <h3 translate>Create a Reminder</h3>

<form [formGroup]="form" (submit)="submit()">
<div class="modal-body">
<c8y-asset-selector-miller class="m-b-24"
[label]="'Assign to'"
[selectedDevice]="asset"
[isLoading]="isLoading"
[config]="{
groupsSelectable: true,
singleColumn: true,
columnHeaders: true,
showFilter: true,
search: true
}"
(onSelected)="assetSelected($event.items)"
></c8y-asset-selector-miller>

<formly-form [form]="form" [fields]="fields" [model]="reminder"></formly-form>
</div>


<div class="modal-footer">
<button type="button" class="btn btn-default" (click)="close()" translate>Cancel</button>

Expand Down

This file was deleted.

35 changes: 12 additions & 23 deletions plugin/components/reminder-modal/reminder-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { Reminder, ReminderStatus, REMINDER_TEXT_LENGTH, REMINDER_TYPE } from '.

@Component({
selector: 'c8y-reminder-modal',
templateUrl: './reminder-modal.component.html',
styleUrls: ['./reminder-modal.component.less']
templateUrl: './reminder-modal.component.html'
})
export class ReminderModalComponent implements OnInit {
isLoading = false;
Expand All @@ -33,15 +32,15 @@ export class ReminderModalComponent implements OnInit {
fields: FormlyFieldConfig[] = [
{
fieldGroup: [
// {
// key: 'source.name',
// type: 'input',
// props: {
// label: this.translateService.instant('Attach to'),
// required: true,
// disabled: true
// }
// },
{
key: 'source',
type: 'asset',
props: {
label: this.translateService.instant('Attach to'),
required: true,
asset: this.asset
}
},
{
key: 'text',
type: 'input',
Expand Down Expand Up @@ -74,28 +73,18 @@ export class ReminderModalComponent implements OnInit {

ngOnInit(): void {
this.asset = this.getAssetFromRoute(this.activatedRoute.snapshot);
this.reminder.source = { id: this.asset.id, name: this.asset.name };
}

close() {
this.bsModalRef.hide();
}

assetSelected(asset: Partial<IManagedObject>): void {
if (!asset || !asset.id) return;

this.asset = {
id: asset.id,
name: asset.name
};
}

async submit(): Promise<void> {
this.isLoading = true;

const reminder: IEvent = {
source: {
id: `${this.asset.id}`
},
source: this.reminder.source,
type: REMINDER_TYPE,
time: moment(this.reminder.time).toISOString(),
text: this.reminder.text,
Expand Down
14 changes: 12 additions & 2 deletions plugin/reminder-plugin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AssetSelectorModule } from '@c8y/ngx-components/assets-navigator';
import { FormlyModule } from '@ngx-formly/core';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { MomentModule } from 'ngx-moment';
import { AssetFieldType } from './components/asset.formly/asset.formly.component';
import { ReminderDrawerComponent } from './components/reminder-drawer/reminder-drawer.component';
import { ReminderIndicatorComponent } from './components/reminder-indicator/reminder-indicator.component';
import { ReminderModalComponent } from './components/reminder-modal/reminder-modal.component';
Expand All @@ -21,11 +22,20 @@ import { ReminderService } from './services/reminder.service';
AssetSelectorModule,
MomentModule,
FormlyModule.forChild({
types: [{ name: 'time', component: TimeFieldType }]
types: [
{ name: 'time', component: TimeFieldType },
{ name: 'asset', component: AssetFieldType }
]
}),
TooltipModule
],
declarations: [ReminderDrawerComponent, ReminderIndicatorComponent, ReminderModalComponent, TimeFieldType],
declarations: [
ReminderDrawerComponent,
ReminderIndicatorComponent,
ReminderModalComponent,
TimeFieldType,
AssetFieldType
],
providers: [
ReminderService,
EventRealtimeService,
Expand Down

0 comments on commit abb56cd

Please sign in to comment.