63 changed files with 2412 additions and 142 deletions
@ -0,0 +1,56 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Injectable} from '@angular/core'; |
||||
|
import {defaultHttpOptions} from './http-utils'; |
||||
|
import {Observable} from 'rxjs/index'; |
||||
|
import {HttpClient} from '@angular/common/http'; |
||||
|
import {PageLink} from '@shared/models/page/page-link'; |
||||
|
import {PageData} from '@shared/models/page/page-data'; |
||||
|
import {RuleChain} from '@shared/models/rule-chain.models'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root' |
||||
|
}) |
||||
|
export class RuleChainService { |
||||
|
|
||||
|
constructor( |
||||
|
private http: HttpClient |
||||
|
) { } |
||||
|
|
||||
|
public getRuleChains(pageLink: PageLink, ignoreErrors: boolean = false, |
||||
|
ignoreLoading: boolean = false): Observable<PageData<RuleChain>> { |
||||
|
return this.http.get<PageData<RuleChain>>(`/api/ruleChains${pageLink.toQuery()}`, |
||||
|
defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public getRuleChain(ruleChainId: string, ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable<RuleChain> { |
||||
|
return this.http.get<RuleChain>(`/api/ruleChain/${ruleChainId}`, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public saveRuleChain(ruleChain: RuleChain, ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable<RuleChain> { |
||||
|
return this.http.post<RuleChain>('/api/ruleChain', ruleChain, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public deleteRuleChain(ruleChainId: string, ignoreErrors: boolean = false, ignoreLoading: boolean = false) { |
||||
|
return this.http.delete(`/api/ruleChain/${ruleChainId}`, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public setRootRuleChain(ruleChainId: string, ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable<RuleChain> { |
||||
|
return this.http.post<RuleChain>(`/api/ruleChain/${ruleChainId}/root`, null, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Injectable} from '@angular/core'; |
||||
|
import {defaultHttpOptions} from './http-utils'; |
||||
|
import {Observable} from 'rxjs/index'; |
||||
|
import {HttpClient} from '@angular/common/http'; |
||||
|
import {PageLink} from '@shared/models/page/page-link'; |
||||
|
import {PageData} from '@shared/models/page/page-data'; |
||||
|
import {WidgetsBundle} from '@shared/models/widgets-bundle.model'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root' |
||||
|
}) |
||||
|
export class WidgetService { |
||||
|
|
||||
|
constructor( |
||||
|
private http: HttpClient |
||||
|
) { } |
||||
|
|
||||
|
public getWidgetBundles(pageLink: PageLink, ignoreErrors: boolean = false, |
||||
|
ignoreLoading: boolean = false): Observable<PageData<WidgetsBundle>> { |
||||
|
return this.http.get<PageData<WidgetsBundle>>(`/api/widgetsBundles${pageLink.toQuery()}`, |
||||
|
defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public getWidgetsBundle(widgetsBundleId: string, |
||||
|
ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable<WidgetsBundle> { |
||||
|
return this.http.get<WidgetsBundle>(`/api/widgetsBundle/${widgetsBundleId}`, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public saveWidgetsBundle(widgetsBundle: WidgetsBundle, |
||||
|
ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable<WidgetsBundle> { |
||||
|
return this.http.post<WidgetsBundle>('/api/widgetsBundle', widgetsBundle, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
public deleteWidgetsBundle(widgetsBundleId: string, ignoreErrors: boolean = false, ignoreLoading: boolean = false) { |
||||
|
return this.http.delete(`/api/widgetsBundle/${widgetsBundleId}`, defaultHttpOptions(ignoreLoading, ignoreErrors)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div class="tb-details-buttons"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'open')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'dashboard.open-dashboard' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'export')" |
||||
|
[fxShow]="!isEdit && dashboardScope === 'tenant'"> |
||||
|
{{'dashboard.export' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'makePublic')" |
||||
|
[fxShow]="!isEdit && dashboardScope === 'tenant' && !isPublic(entity)"> |
||||
|
{{'dashboard.make-public' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'makePrivate')" |
||||
|
[fxShow]="!isEdit && (dashboardScope === 'tenant' && isPublic(entity) |
||||
|
|| dashboardScope === 'customer' && isCurrentPublicCustomer(entity))"> |
||||
|
{{'dashboard.make-private' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'manageAssignedCustomers')" |
||||
|
[fxShow]="!isEdit && dashboardScope === 'tenant'"> |
||||
|
{{'dashboard.manage-assigned-customers' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'unassignFromCustomer')" |
||||
|
[fxShow]="!isEdit && dashboardScope === 'customer' && !isCurrentPublicCustomer(entity)"> |
||||
|
{{ 'dashboard.unassign-from-customer' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'delete')" |
||||
|
[fxShow]="!hideDelete() && !isEdit"> |
||||
|
{{'dashboard.delete' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
<div class="mat-padding" fxLayout="column"> |
||||
|
<mat-form-field class="mat-block" |
||||
|
[fxShow]="!isEdit && assignedCustomersText |
||||
|
&& dashboardScope === 'tenant'"> |
||||
|
<mat-label translate>dashboard.assignedToCustomers</mat-label> |
||||
|
<input matInput disabled [ngModel]="assignedCustomersText"> |
||||
|
</mat-form-field> |
||||
|
<div fxLayout="column" [fxShow]="!isEdit && (dashboardScope === 'tenant' && isPublic(entity) |
||||
|
|| dashboardScope === 'customer' && isCurrentPublicCustomer(entity))"> |
||||
|
<tb-social-share-panel style="padding-bottom: 10px;" |
||||
|
shareTitle="{{ 'dashboard.socialshare-title' | translate:{dashboardTitle: entity?.title} }}" |
||||
|
shareText="{{ 'dashboard.socialshare-text' | translate:{dashboardTitle: entity?.title} }}" |
||||
|
shareLink="{{ publicLink }}" |
||||
|
shareHashTags="thingsboard, iot"> |
||||
|
</tb-social-share-panel> |
||||
|
<div fxLayout="row"> |
||||
|
<mat-form-field class="mat-block" fxFlex> |
||||
|
<mat-label translate>dashboard.public-link</mat-label> |
||||
|
<input matInput disabled [ngModel]="publicLink"> |
||||
|
</mat-form-field> |
||||
|
<button mat-button mat-icon-button style="margin-top: 8px;" |
||||
|
ngxClipboard |
||||
|
(cbOnSuccess)="onPublicLinkCopied($event)" |
||||
|
cbContent="{{ publicLink }}" |
||||
|
matTooltipPosition="above" |
||||
|
matTooltip="{{ 'dashboard.copy-public-link' | translate }}"> |
||||
|
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<form #entityNgForm="ngForm" [formGroup]="entityForm"> |
||||
|
<fieldset [disabled]="(isLoading$ | async) || !isEdit"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>dashboard.title</mat-label> |
||||
|
<input matInput formControlName="title" required> |
||||
|
<mat-error *ngIf="entityForm.get('title').hasError('required')"> |
||||
|
{{ 'dashboard.title-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<div formGroupName="configuration" fxLayout="column"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>dashboard.description</mat-label> |
||||
|
<textarea matInput formControlName="description" rows="2"></textarea> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</div> |
||||
@ -0,0 +1,19 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2019 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
|
||||
|
:host { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Component} from '@angular/core'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {EntityComponent} from '@shared/components/entity/entity.component'; |
||||
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
||||
|
import {ActionNotificationShow} from '@core/notification/notification.actions'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
import { |
||||
|
Dashboard, |
||||
|
isPublicDashboard, |
||||
|
getDashboardAssignedCustomersText, |
||||
|
isCurrentPublicDashboardCustomer, |
||||
|
DashboardInfo |
||||
|
} from '@shared/models/dashboard.models'; |
||||
|
import {DashboardService} from '@core/http/dashboard.service'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-dashboard-form', |
||||
|
templateUrl: './dashboard-form.component.html', |
||||
|
styleUrls: ['./dashboard-form.component.scss'] |
||||
|
}) |
||||
|
export class DashboardFormComponent extends EntityComponent<Dashboard | DashboardInfo> { |
||||
|
|
||||
|
dashboardScope: 'tenant' | 'customer' | 'customer_user'; |
||||
|
customerId: string; |
||||
|
|
||||
|
publicLink: string; |
||||
|
assignedCustomersText: string; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected translate: TranslateService, |
||||
|
private dashboardService: DashboardService, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
this.dashboardScope = this.entitiesTableConfig.componentsData.dashboardScope; |
||||
|
this.customerId = this.entitiesTableConfig.componentsData.customerId; |
||||
|
super.ngOnInit(); |
||||
|
} |
||||
|
|
||||
|
isPublic(entity: Dashboard): boolean { |
||||
|
return isPublicDashboard(entity); |
||||
|
} |
||||
|
|
||||
|
isCurrentPublicCustomer(entity: Dashboard): boolean { |
||||
|
return isCurrentPublicDashboardCustomer(entity, this.customerId); |
||||
|
} |
||||
|
|
||||
|
hideDelete() { |
||||
|
if (this.entitiesTableConfig) { |
||||
|
return !this.entitiesTableConfig.deleteEnabled(this.entity); |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
buildForm(entity: Dashboard): FormGroup { |
||||
|
this.updateFields(entity); |
||||
|
return this.fb.group( |
||||
|
{ |
||||
|
title: [entity ? entity.title : '', [Validators.required]], |
||||
|
configuration: this.fb.group( |
||||
|
{ |
||||
|
description: [entity && entity.configuration ? entity.configuration.description : ''], |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
updateForm(entity: Dashboard) { |
||||
|
this.updateFields(entity); |
||||
|
this.entityForm.patchValue({title: entity.title}); |
||||
|
this.entityForm.patchValue({configuration: {description: entity.configuration ? entity.configuration.description : ''}}); |
||||
|
} |
||||
|
|
||||
|
onPublicLinkCopied($event) { |
||||
|
this.store.dispatch(new ActionNotificationShow( |
||||
|
{ |
||||
|
message: this.translate.instant('dashboard.public-link-copied-message'), |
||||
|
type: 'success', |
||||
|
duration: 750, |
||||
|
verticalPosition: 'bottom', |
||||
|
horizontalPosition: 'right' |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
private updateFields(entity: Dashboard): void { |
||||
|
this.assignedCustomersText = getDashboardAssignedCustomersText(entity); |
||||
|
this.publicLink = this.dashboardService.getPublicDashboardLink(entity); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {RouterModule, Routes} from '@angular/router'; |
||||
|
|
||||
|
import {EntitiesTableComponent} from '@shared/components/entity/entities-table.component'; |
||||
|
import {Authority} from '@shared/models/authority.enum'; |
||||
|
import {DashboardsTableConfigResolver} from './dashboards-table-config.resolver'; |
||||
|
|
||||
|
const routes: Routes = [ |
||||
|
{ |
||||
|
path: 'dashboards', |
||||
|
data: { |
||||
|
breadcrumb: { |
||||
|
label: 'dashboard.dashboards', |
||||
|
icon: 'dashboard' |
||||
|
} |
||||
|
}, |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '', |
||||
|
component: EntitiesTableComponent, |
||||
|
data: { |
||||
|
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
||||
|
title: 'dashboard.dashboards', |
||||
|
dashboardsType: 'tenant' |
||||
|
}, |
||||
|
resolve: { |
||||
|
entitiesTableConfig: DashboardsTableConfigResolver |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
]; |
||||
|
|
||||
|
@NgModule({ |
||||
|
imports: [RouterModule.forChild(routes)], |
||||
|
exports: [RouterModule], |
||||
|
providers: [ |
||||
|
DashboardsTableConfigResolver |
||||
|
] |
||||
|
}) |
||||
|
export class DashboardRoutingModule { } |
||||
@ -0,0 +1,41 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {CommonModule} from '@angular/common'; |
||||
|
import {SharedModule} from '@shared/shared.module'; |
||||
|
import {HomeDialogsModule} from '../../dialogs/home-dialogs.module'; |
||||
|
import {DashboardFormComponent} from '@modules/home/pages/dashboard/dashboard-form.component'; |
||||
|
import {ManageDashboardCustomersDialogComponent} from '@modules/home/pages/dashboard/manage-dashboard-customers-dialog.component'; |
||||
|
import {DashboardRoutingModule} from './dashboard-routing.module'; |
||||
|
|
||||
|
@NgModule({ |
||||
|
entryComponents: [ |
||||
|
DashboardFormComponent, |
||||
|
ManageDashboardCustomersDialogComponent |
||||
|
], |
||||
|
declarations: [ |
||||
|
DashboardFormComponent, |
||||
|
ManageDashboardCustomersDialogComponent |
||||
|
], |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
SharedModule, |
||||
|
HomeDialogsModule, |
||||
|
DashboardRoutingModule |
||||
|
] |
||||
|
}) |
||||
|
export class DashboardModule { } |
||||
@ -0,0 +1,484 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Injectable} from '@angular/core'; |
||||
|
|
||||
|
import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router'; |
||||
|
import { |
||||
|
CellActionDescriptor, |
||||
|
checkBoxCell, |
||||
|
DateEntityTableColumn, |
||||
|
EntityTableColumn, |
||||
|
EntityTableConfig, |
||||
|
GroupActionDescriptor, |
||||
|
HeaderActionDescriptor |
||||
|
} from '@shared/components/entity/entities-table-config.models'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
import {DatePipe} from '@angular/common'; |
||||
|
import {EntityType, entityTypeResources, entityTypeTranslations} from '@shared/models/entity-type.models'; |
||||
|
import {EntityAction} from '@shared/components/entity/entity-component.models'; |
||||
|
import {forkJoin, Observable, of} from 'rxjs'; |
||||
|
import {select, Store} from '@ngrx/store'; |
||||
|
import {selectAuthUser} from '@core/auth/auth.selectors'; |
||||
|
import {map, mergeMap, take, tap} from 'rxjs/operators'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {Authority} from '@app/shared/models/authority.enum'; |
||||
|
import {CustomerService} from '@core/http/customer.service'; |
||||
|
import {Customer} from '@app/shared/models/customer.model'; |
||||
|
import {MatDialog} from '@angular/material'; |
||||
|
import {DialogService} from '@core/services/dialog.service'; |
||||
|
import { |
||||
|
AddEntitiesToCustomerDialogComponent, |
||||
|
AddEntitiesToCustomerDialogData |
||||
|
} from '../../dialogs/add-entities-to-customer-dialog.component'; |
||||
|
import { |
||||
|
Dashboard, |
||||
|
DashboardInfo, |
||||
|
getDashboardAssignedCustomersText, |
||||
|
isCurrentPublicDashboardCustomer, |
||||
|
isPublicDashboard |
||||
|
} from '@app/shared/models/dashboard.models'; |
||||
|
import {DashboardService} from '@app/core/http/dashboard.service'; |
||||
|
import {DashboardFormComponent} from '@modules/home/pages/dashboard/dashboard-form.component'; |
||||
|
import { |
||||
|
ManageDashboardCustomersActionType, |
||||
|
ManageDashboardCustomersDialogComponent, |
||||
|
ManageDashboardCustomersDialogData |
||||
|
} from './manage-dashboard-customers-dialog.component'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<DashboardInfo | Dashboard>> { |
||||
|
|
||||
|
private readonly config: EntityTableConfig<DashboardInfo | Dashboard> = new EntityTableConfig<DashboardInfo | Dashboard>(); |
||||
|
|
||||
|
constructor(private store: Store<AppState>, |
||||
|
private dashboardService: DashboardService, |
||||
|
private customerService: CustomerService, |
||||
|
private dialogService: DialogService, |
||||
|
private translate: TranslateService, |
||||
|
private datePipe: DatePipe, |
||||
|
private router: Router, |
||||
|
private dialog: MatDialog) { |
||||
|
|
||||
|
this.config.entityType = EntityType.DASHBOARD; |
||||
|
this.config.entityComponent = DashboardFormComponent; |
||||
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.DASHBOARD); |
||||
|
this.config.entityResources = entityTypeResources.get(EntityType.DASHBOARD); |
||||
|
|
||||
|
this.config.deleteEntityTitle = dashboard => |
||||
|
this.translate.instant('dashboard.delete-dashboard-title', { dashboardTitle: dashboard.title }); |
||||
|
this.config.deleteEntityContent = () => this.translate.instant('dashboard.delete-dashboard-text'); |
||||
|
this.config.deleteEntitiesTitle = count => this.translate.instant('dashboard.delete-dashboards-title', {count}); |
||||
|
this.config.deleteEntitiesContent = () => this.translate.instant('dashboard.delete-dashboards-text'); |
||||
|
|
||||
|
this.config.loadEntity = id => this.dashboardService.getDashboard(id.id); |
||||
|
this.config.saveEntity = dashboard => { |
||||
|
return this.dashboardService.saveDashboard(dashboard as Dashboard); |
||||
|
}; |
||||
|
this.config.onEntityAction = action => this.onDashboardAction(action); |
||||
|
this.config.detailsReadonly = () => this.config.componentsData.dashboardScope === 'customer_user'; |
||||
|
} |
||||
|
|
||||
|
resolve(route: ActivatedRouteSnapshot): Observable<EntityTableConfig<DashboardInfo | Dashboard>> { |
||||
|
const routeParams = route.params; |
||||
|
this.config.componentsData = { |
||||
|
dashboardScope: route.data.dashboardsType, |
||||
|
customerId: routeParams.customerId |
||||
|
}; |
||||
|
return this.store.pipe(select(selectAuthUser), take(1)).pipe( |
||||
|
tap((authUser) => { |
||||
|
if (authUser.authority === Authority.CUSTOMER_USER) { |
||||
|
this.config.componentsData.dashboardScope = 'customer_user'; |
||||
|
this.config.componentsData.customerId = authUser.customerId; |
||||
|
} |
||||
|
}), |
||||
|
mergeMap(() => |
||||
|
this.config.componentsData.customerId ? |
||||
|
this.customerService.getCustomer(this.config.componentsData.customerId) : of(null as Customer) |
||||
|
), |
||||
|
map((parentCustomer) => { |
||||
|
if (parentCustomer) { |
||||
|
if (parentCustomer.additionalInfo && parentCustomer.additionalInfo.isPublic) { |
||||
|
this.config.tableTitle = this.translate.instant('customer.public-dashboards'); |
||||
|
} else { |
||||
|
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('dashboard.dashboards'); |
||||
|
} |
||||
|
} else { |
||||
|
this.config.tableTitle = this.translate.instant('dashboard.dashboards'); |
||||
|
} |
||||
|
this.config.columns = this.configureColumns(this.config.componentsData.dashboardScope); |
||||
|
this.configureEntityFunctions(this.config.componentsData.dashboardScope); |
||||
|
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.dashboardScope); |
||||
|
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.dashboardScope); |
||||
|
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.dashboardScope); |
||||
|
this.config.addEnabled = this.config.componentsData.dashboardScope !== 'customer_user'; |
||||
|
this.config.entitiesDeleteEnabled = this.config.componentsData.dashboardScope === 'tenant'; |
||||
|
this.config.deleteEnabled = () => this.config.componentsData.dashboardScope === 'tenant'; |
||||
|
return this.config; |
||||
|
}) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
configureColumns(dashboardScope: string): Array<EntityTableColumn<DashboardInfo>> { |
||||
|
const columns: Array<EntityTableColumn<DashboardInfo>> = [ |
||||
|
new DateEntityTableColumn<DashboardInfo>('createdTime', 'dashboard.created-time', this.datePipe, '150px'), |
||||
|
new EntityTableColumn<DashboardInfo>('title', 'dashboard.title') |
||||
|
]; |
||||
|
if (dashboardScope === 'tenant') { |
||||
|
columns.push( |
||||
|
new EntityTableColumn<DashboardInfo>('customersTitle', 'dashboard.assignedToCustomers', |
||||
|
'100%', entity => { |
||||
|
return getDashboardAssignedCustomersText(entity); |
||||
|
}, () => ({}), false), |
||||
|
new EntityTableColumn<DashboardInfo>('dashboardIsPublic', 'dashboard.public', '60px', |
||||
|
entity => { |
||||
|
return checkBoxCell(isPublicDashboard(entity)); |
||||
|
}, () => ({}), false), |
||||
|
); |
||||
|
} |
||||
|
return columns; |
||||
|
} |
||||
|
|
||||
|
configureEntityFunctions(dashboardScope: string): void { |
||||
|
if (dashboardScope === 'tenant') { |
||||
|
this.config.entitiesFetchFunction = pageLink => |
||||
|
this.dashboardService.getTenantDashboards(pageLink); |
||||
|
this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id); |
||||
|
} else { |
||||
|
this.config.entitiesFetchFunction = pageLink => |
||||
|
this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink); |
||||
|
this.config.deleteEntity = id => |
||||
|
this.dashboardService.unassignDashboardFromCustomer(this.config.componentsData.customerId, id.id); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
configureCellActions(dashboardScope: string): Array<CellActionDescriptor<DashboardInfo>> { |
||||
|
const actions: Array<CellActionDescriptor<DashboardInfo>> = []; |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.open-dashboard'), |
||||
|
icon: 'dashboard', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.openDashboard($event, entity) |
||||
|
} |
||||
|
); |
||||
|
if (dashboardScope === 'tenant') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.export'), |
||||
|
icon: 'file_download', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.exportDashboard($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.make-public'), |
||||
|
icon: 'share', |
||||
|
isEnabled: (entity) => !isPublicDashboard(entity), |
||||
|
onAction: ($event, entity) => this.makePublic($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.make-private'), |
||||
|
icon: 'reply', |
||||
|
isEnabled: (entity) => isPublicDashboard(entity), |
||||
|
onAction: ($event, entity) => this.makePrivate($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.manage-assigned-customers'), |
||||
|
icon: 'assignment_ind', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.manageAssignedCustomers($event, entity) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
if (dashboardScope === 'customer') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.export'), |
||||
|
icon: 'file_download', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.exportDashboard($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.make-private'), |
||||
|
icon: 'reply', |
||||
|
isEnabled: (entity) => isCurrentPublicDashboardCustomer(entity, this.config.componentsData.customerId), |
||||
|
onAction: ($event, entity) => this.makePrivate($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.unassign-from-customer'), |
||||
|
icon: 'assignment_return', |
||||
|
isEnabled: (entity) => !isCurrentPublicDashboardCustomer(entity, this.config.componentsData.customerId), |
||||
|
onAction: ($event, entity) => this.unassignFromCustomer($event, entity, this.config.componentsData.customerId) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
return actions; |
||||
|
} |
||||
|
|
||||
|
configureGroupActions(dashboardScope: string): Array<GroupActionDescriptor<DashboardInfo>> { |
||||
|
const actions: Array<GroupActionDescriptor<DashboardInfo>> = []; |
||||
|
if (dashboardScope === 'tenant') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.assign-dashboards'), |
||||
|
icon: 'assignment_ind', |
||||
|
isEnabled: true, |
||||
|
onAction: ($event, entities) => this.assignDashboardsToCustomers($event, entities.map((entity) => entity.id.id)) |
||||
|
} |
||||
|
); |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.unassign-dashboards'), |
||||
|
icon: 'assignment_return', |
||||
|
isEnabled: true, |
||||
|
onAction: ($event, entities) => this.unassignDashboardsFromCustomers($event, entities.map((entity) => entity.id.id)) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
if (dashboardScope === 'customer') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.unassign-dashboards'), |
||||
|
icon: 'assignment_return', |
||||
|
isEnabled: true, |
||||
|
onAction: ($event, entities) => |
||||
|
this.unassignDashboardsFromCustomer($event, entities.map((entity) => entity.id.id), this.config.componentsData.customerId) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
return actions; |
||||
|
} |
||||
|
|
||||
|
configureAddActions(dashboardScope: string): Array<HeaderActionDescriptor> { |
||||
|
const actions: Array<HeaderActionDescriptor> = []; |
||||
|
if (dashboardScope === 'tenant') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.create-new-dashboard'), |
||||
|
icon: 'insert_drive_file', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.config.table.addEntity($event) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.import'), |
||||
|
icon: 'file_upload', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.importDashboard($event) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
if (dashboardScope === 'customer') { |
||||
|
actions.push( |
||||
|
{ |
||||
|
name: this.translate.instant('dashboard.assign-new-dashboard'), |
||||
|
icon: 'add', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.addDashboardsToCustomer($event) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
return actions; |
||||
|
} |
||||
|
|
||||
|
openDashboard($event: Event, dashboard: DashboardInfo) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
// this.router.navigateByUrl(`customers/${customer.id.id}/users`);
|
||||
|
} |
||||
|
|
||||
|
importDashboard($event: Event) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
exportDashboard($event: Event, dashboard: DashboardInfo) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
addDashboardsToCustomer($event: Event) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialog.open<AddEntitiesToCustomerDialogComponent, AddEntitiesToCustomerDialogData, |
||||
|
boolean>(AddEntitiesToCustomerDialogComponent, { |
||||
|
disableClose: true, |
||||
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
||||
|
data: { |
||||
|
customerId: this.config.componentsData.customerId, |
||||
|
entityType: EntityType.DASHBOARD |
||||
|
} |
||||
|
}).afterClosed() |
||||
|
.subscribe((res) => { |
||||
|
if (res) { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
makePublic($event: Event, dashboard: DashboardInfo) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dashboardService.makeDashboardPublic(dashboard.id.id).subscribe( |
||||
|
(publicDashboard) => { |
||||
|
// TODO:
|
||||
|
|
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
makePrivate($event: Event, dashboard: DashboardInfo) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('dashboard.make-private-dashboard-title', {dashboardTitle: dashboard.title}), |
||||
|
this.translate.instant('dashboard.make-private-dashboard-text'), |
||||
|
this.translate.instant('action.no'), |
||||
|
this.translate.instant('action.yes'), |
||||
|
true |
||||
|
).subscribe((res) => { |
||||
|
if (res) { |
||||
|
this.dashboardService.makeDashboardPrivate(dashboard.id.id).subscribe( |
||||
|
() => { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
manageAssignedCustomers($event: Event, dashboard: DashboardInfo) { |
||||
|
const assignedCustomersIds = dashboard.assignedCustomers ? |
||||
|
dashboard.assignedCustomers.map(customerInfo => customerInfo.customerId.id) : []; |
||||
|
this.showManageAssignedCustomersDialog($event, [dashboard.id.id], 'manage', assignedCustomersIds); |
||||
|
} |
||||
|
|
||||
|
assignDashboardsToCustomers($event: Event, dashboardIds: Array<string>) { |
||||
|
this.showManageAssignedCustomersDialog($event, dashboardIds, 'assign'); |
||||
|
} |
||||
|
|
||||
|
unassignDashboardsFromCustomers($event: Event, dashboardIds: Array<string>) { |
||||
|
this.showManageAssignedCustomersDialog($event, dashboardIds, 'unassign'); |
||||
|
} |
||||
|
|
||||
|
showManageAssignedCustomersDialog($event: Event, dashboardIds: Array<string>, |
||||
|
actionType: ManageDashboardCustomersActionType, |
||||
|
assignedCustomersIds?: Array<string>) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialog.open<ManageDashboardCustomersDialogComponent, ManageDashboardCustomersDialogData, |
||||
|
boolean>(ManageDashboardCustomersDialogComponent, { |
||||
|
disableClose: true, |
||||
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
||||
|
data: { |
||||
|
dashboardIds, |
||||
|
actionType, |
||||
|
assignedCustomersIds |
||||
|
} |
||||
|
}).afterClosed() |
||||
|
.subscribe((res) => { |
||||
|
if (res) { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
unassignFromCustomer($event: Event, dashboard: DashboardInfo, customerId: string) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('dashboard.unassign-dashboard-title', {dashboardTitle: dashboard.title}), |
||||
|
this.translate.instant('dashboard.unassign-dashboard-text'), |
||||
|
this.translate.instant('action.no'), |
||||
|
this.translate.instant('action.yes'), |
||||
|
true |
||||
|
).subscribe((res) => { |
||||
|
if (res) { |
||||
|
this.dashboardService.unassignDashboardFromCustomer(customerId, dashboard.id.id).subscribe( |
||||
|
() => { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
unassignDashboardsFromCustomer($event: Event, dashboardIds: Array<string>, customerId: string) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('dashboard.unassign-dashboards-title', {count: dashboardIds.length}), |
||||
|
this.translate.instant('dashboard.unassign-dashboards-text'), |
||||
|
this.translate.instant('action.no'), |
||||
|
this.translate.instant('action.yes'), |
||||
|
true |
||||
|
).subscribe((res) => { |
||||
|
if (res) { |
||||
|
const tasks: Observable<any>[] = []; |
||||
|
dashboardIds.forEach( |
||||
|
(dashboardId) => { |
||||
|
tasks.push(this.dashboardService.unassignDashboardFromCustomer(customerId, dashboardId)); |
||||
|
} |
||||
|
); |
||||
|
forkJoin(tasks).subscribe( |
||||
|
() => { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
onDashboardAction(action: EntityAction<DashboardInfo>): boolean { |
||||
|
switch (action.action) { |
||||
|
case 'open': |
||||
|
this.openDashboard(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'export': |
||||
|
this.exportDashboard(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'makePublic': |
||||
|
this.makePublic(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'makePrivate': |
||||
|
this.makePrivate(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'manageAssignedCustomers': |
||||
|
this.manageAssignedCustomers(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'unassignFromCustomer': |
||||
|
this.unassignFromCustomer(action.event, action.entity, this.config.componentsData.customerId); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<form #dashboardCustomersForm="ngForm" style="width: 600px;" |
||||
|
[formGroup]="dashboardCustomersFormGroup" (ngSubmit)="submit()"> |
||||
|
<mat-toolbar fxLayout="row" color="primary"> |
||||
|
<h2>{{ titleText | translate }}</h2> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-button mat-icon-button |
||||
|
(click)="cancel()" |
||||
|
type="button"> |
||||
|
<mat-icon class="material-icons">close</mat-icon> |
||||
|
</button> |
||||
|
</mat-toolbar> |
||||
|
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
||||
|
</mat-progress-bar> |
||||
|
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
||||
|
<div mat-dialog-content> |
||||
|
<fieldset [disabled]="isLoading$ | async"> |
||||
|
<span>{{ labelText | translate }}</span> |
||||
|
<tb-entity-list |
||||
|
formControlName="assignedCustomerIds" |
||||
|
required |
||||
|
[entityType]="entityType.CUSTOMER"> |
||||
|
</tb-entity-list> |
||||
|
</fieldset> |
||||
|
</div> |
||||
|
<div mat-dialog-actions fxLayout="row"> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-button mat-raised-button color="primary" |
||||
|
type="submit" |
||||
|
[disabled]="(isLoading$ | async) || dashboardCustomersForm.invalid |
||||
|
|| !dashboardCustomersForm.dirty"> |
||||
|
{{ actionName | translate }} |
||||
|
</button> |
||||
|
<button mat-button color="primary" |
||||
|
style="margin-right: 20px;" |
||||
|
type="button" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="cancel()" cdkFocusInitial> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</form> |
||||
@ -0,0 +1,129 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Component, Inject, OnInit, SkipSelf} from '@angular/core'; |
||||
|
import {ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef} from '@angular/material'; |
||||
|
import {PageComponent} from '@shared/components/page.component'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm} from '@angular/forms'; |
||||
|
import {EntityType} from '@shared/models/entity-type.models'; |
||||
|
import {DashboardService} from '@core/http/dashboard.service'; |
||||
|
import {forkJoin, Observable} from 'rxjs'; |
||||
|
|
||||
|
export type ManageDashboardCustomersActionType = 'assign' | 'manage' | 'unassign'; |
||||
|
|
||||
|
export interface ManageDashboardCustomersDialogData { |
||||
|
actionType: ManageDashboardCustomersActionType; |
||||
|
dashboardIds: Array<string>; |
||||
|
assignedCustomersIds?: Array<string>; |
||||
|
} |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-manage-dashboard-customers-dialog', |
||||
|
templateUrl: './manage-dashboard-customers-dialog.component.html', |
||||
|
providers: [{provide: ErrorStateMatcher, useExisting: ManageDashboardCustomersDialogComponent}], |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class ManageDashboardCustomersDialogComponent extends PageComponent implements OnInit, ErrorStateMatcher { |
||||
|
|
||||
|
dashboardCustomersFormGroup: FormGroup; |
||||
|
|
||||
|
submitted = false; |
||||
|
|
||||
|
entityType = EntityType; |
||||
|
|
||||
|
titleText: string; |
||||
|
labelText: string; |
||||
|
actionName: string; |
||||
|
|
||||
|
assignedCustomersIds: string[]; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
@Inject(MAT_DIALOG_DATA) public data: ManageDashboardCustomersDialogData, |
||||
|
private dashboardService: DashboardService, |
||||
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
||||
|
public dialogRef: MatDialogRef<ManageDashboardCustomersDialogComponent, boolean>, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
|
||||
|
this.assignedCustomersIds = data.assignedCustomersIds || []; |
||||
|
switch (data.actionType) { |
||||
|
case 'assign': |
||||
|
this.titleText = 'dashboard.assign-to-customers'; |
||||
|
this.labelText = 'dashboard.assign-to-customers-text'; |
||||
|
this.actionName = 'action.assign'; |
||||
|
break; |
||||
|
case 'manage': |
||||
|
this.titleText = 'dashboard.manage-assigned-customers'; |
||||
|
this.labelText = 'dashboard.assigned-customers'; |
||||
|
this.actionName = 'action.update'; |
||||
|
break; |
||||
|
case 'unassign': |
||||
|
this.titleText = 'dashboard.unassign-from-customers'; |
||||
|
this.labelText = 'dashboard.unassign-from-customers-text'; |
||||
|
this.actionName = 'action.unassign'; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.dashboardCustomersFormGroup = this.fb.group({ |
||||
|
assignedCustomerIds: [[...this.assignedCustomersIds]] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
||||
|
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
||||
|
const customErrorState = !!(control && control.invalid && this.submitted); |
||||
|
return originalErrorState || customErrorState; |
||||
|
} |
||||
|
|
||||
|
cancel(): void { |
||||
|
this.dialogRef.close(false); |
||||
|
} |
||||
|
|
||||
|
submit(): void { |
||||
|
this.submitted = true; |
||||
|
const customerIds: Array<string> = this.dashboardCustomersFormGroup.get('assignedCustomerIds').value; |
||||
|
const tasks: Observable<any>[] = []; |
||||
|
|
||||
|
this.data.dashboardIds.forEach( |
||||
|
(dashboardId) => { |
||||
|
tasks.push(this.getManageDashboardCustomersTask(dashboardId, customerIds)); |
||||
|
} |
||||
|
); |
||||
|
forkJoin(tasks).subscribe( |
||||
|
() => { |
||||
|
this.dialogRef.close(true); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private getManageDashboardCustomersTask(dashboardId: string, customerIds: Array<string>): Observable<any> { |
||||
|
switch (this.data.actionType) { |
||||
|
case 'assign': |
||||
|
return this.dashboardService.addDashboardCustomers(dashboardId, customerIds); |
||||
|
break; |
||||
|
case 'manage': |
||||
|
return this.dashboardService.updateDashboardCustomers(dashboardId, customerIds); |
||||
|
break; |
||||
|
case 'unassign': |
||||
|
return this.dashboardService.removeDashboardCustomers(dashboardId, customerIds); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {RouterModule, Routes} from '@angular/router'; |
||||
|
|
||||
|
import {EntitiesTableComponent} from '@shared/components/entity/entities-table.component'; |
||||
|
import {Authority} from '@shared/models/authority.enum'; |
||||
|
import {RuleChainsTableConfigResolver} from '@modules/home/pages/rulechain/rulechains-table-config.resolver'; |
||||
|
|
||||
|
const routes: Routes = [ |
||||
|
{ |
||||
|
path: 'ruleChains', |
||||
|
data: { |
||||
|
breadcrumb: { |
||||
|
label: 'rulechain.rulechains', |
||||
|
icon: 'settings_ethernet' |
||||
|
} |
||||
|
}, |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '', |
||||
|
component: EntitiesTableComponent, |
||||
|
data: { |
||||
|
auth: [Authority.TENANT_ADMIN], |
||||
|
title: 'rulechain.rulechains' |
||||
|
}, |
||||
|
resolve: { |
||||
|
entitiesTableConfig: RuleChainsTableConfigResolver |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
]; |
||||
|
|
||||
|
@NgModule({ |
||||
|
imports: [RouterModule.forChild(routes)], |
||||
|
exports: [RouterModule], |
||||
|
providers: [ |
||||
|
RuleChainsTableConfigResolver |
||||
|
] |
||||
|
}) |
||||
|
export class RuleChainRoutingModule { } |
||||
@ -0,0 +1,75 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div class="tb-details-buttons"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'open')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'rulechain.open-rulechain' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'export')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'rulechain.export' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'setRoot')" |
||||
|
[fxShow]="!isEdit && !entity?.root"> |
||||
|
{{'rulechain.set-root' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'delete')" |
||||
|
[fxShow]="!hideDelete() && !isEdit"> |
||||
|
{{'rulechain.delete' | translate }} |
||||
|
</button> |
||||
|
<div fxLayout="row"> |
||||
|
<button mat-raised-button |
||||
|
ngxClipboard |
||||
|
(cbOnSuccess)="onRuleChainIdCopied($event)" |
||||
|
[cbContent]="entity?.id?.id" |
||||
|
[fxShow]="!isEdit"> |
||||
|
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
||||
|
<span translate>rulechain.copyId</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="mat-padding" fxLayout="column"> |
||||
|
<form #entityNgForm="ngForm" [formGroup]="entityForm"> |
||||
|
<fieldset [disabled]="(isLoading$ | async) || !isEdit"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>rulechain.name</mat-label> |
||||
|
<input matInput formControlName="name" required> |
||||
|
<mat-error *ngIf="entityForm.get('name').hasError('required')"> |
||||
|
{{ 'rulechain.name-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-checkbox fxFlex formControlName="debugMode" style="padding-bottom: 16px;"> |
||||
|
{{ 'rulechain.debug-mode' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<div formGroupName="additionalInfo"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>rulechain.description</mat-label> |
||||
|
<textarea matInput formControlName="description" rows="2"></textarea> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</div> |
||||
@ -0,0 +1,19 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2019 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
|
||||
|
:host { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Component} from '@angular/core'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {EntityComponent} from '@shared/components/entity/entity.component'; |
||||
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
||||
|
import {EntityType} from '@shared/models/entity-type.models'; |
||||
|
import {NULL_UUID} from '@shared/models/id/has-uuid'; |
||||
|
import {ActionNotificationShow} from '@core/notification/notification.actions'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
import {AssetInfo} from '@app/shared/models/asset.models'; |
||||
|
import {RuleChain} from "@shared/models/rule-chain.models"; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-rulechain', |
||||
|
templateUrl: './rulechain.component.html', |
||||
|
styleUrls: ['./rulechain.component.scss'] |
||||
|
}) |
||||
|
export class RuleChainComponent extends EntityComponent<RuleChain> { |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected translate: TranslateService, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
hideDelete() { |
||||
|
if (this.entitiesTableConfig) { |
||||
|
return !this.entitiesTableConfig.deleteEnabled(this.entity); |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
buildForm(entity: RuleChain): FormGroup { |
||||
|
return this.fb.group( |
||||
|
{ |
||||
|
name: [entity ? entity.name : '', [Validators.required]], |
||||
|
debugMode: [entity ? entity.debugMode : false], |
||||
|
additionalInfo: this.fb.group( |
||||
|
{ |
||||
|
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
updateForm(entity: RuleChain) { |
||||
|
this.entityForm.patchValue({name: entity.name}); |
||||
|
this.entityForm.patchValue({debugMode: entity.debugMode}); |
||||
|
this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
onRuleChainIdCopied($event) { |
||||
|
this.store.dispatch(new ActionNotificationShow( |
||||
|
{ |
||||
|
message: this.translate.instant('rulechain.idCopiedMessage'), |
||||
|
type: 'success', |
||||
|
duration: 750, |
||||
|
verticalPosition: 'bottom', |
||||
|
horizontalPosition: 'right' |
||||
|
})); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {CommonModule} from '@angular/common'; |
||||
|
import {SharedModule} from '@shared/shared.module'; |
||||
|
import {RuleChainComponent} from '@modules/home/pages/rulechain/rulechain.component'; |
||||
|
import {RuleChainRoutingModule} from '@modules/home/pages/rulechain/rulechain-routing.module'; |
||||
|
|
||||
|
@NgModule({ |
||||
|
entryComponents: [ |
||||
|
RuleChainComponent |
||||
|
], |
||||
|
declarations: [ |
||||
|
RuleChainComponent |
||||
|
], |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
SharedModule, |
||||
|
RuleChainRoutingModule |
||||
|
] |
||||
|
}) |
||||
|
export class RuleChainModule { } |
||||
@ -0,0 +1,176 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Injectable} from '@angular/core'; |
||||
|
|
||||
|
import {Resolve, Router} from '@angular/router'; |
||||
|
import { |
||||
|
checkBoxCell, |
||||
|
DateEntityTableColumn, |
||||
|
EntityTableColumn, |
||||
|
EntityTableConfig |
||||
|
} from '@shared/components/entity/entities-table-config.models'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
import {DatePipe} from '@angular/common'; |
||||
|
import {EntityType, entityTypeResources, entityTypeTranslations} from '@shared/models/entity-type.models'; |
||||
|
import {EntityAction} from '@shared/components/entity/entity-component.models'; |
||||
|
import {RuleChain} from '@shared/models/rule-chain.models'; |
||||
|
import {RuleChainService} from '@core/http/rule-chain.service'; |
||||
|
import {RuleChainComponent} from '@modules/home/pages/rulechain/rulechain.component'; |
||||
|
import {DialogService} from '@core/services/dialog.service'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> { |
||||
|
|
||||
|
private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>(); |
||||
|
|
||||
|
constructor(private ruleChainService: RuleChainService, |
||||
|
private dialogService: DialogService, |
||||
|
private translate: TranslateService, |
||||
|
private datePipe: DatePipe, |
||||
|
private router: Router) { |
||||
|
|
||||
|
this.config.entityType = EntityType.RULE_CHAIN; |
||||
|
this.config.entityComponent = RuleChainComponent; |
||||
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.RULE_CHAIN); |
||||
|
this.config.entityResources = entityTypeResources.get(EntityType.RULE_CHAIN); |
||||
|
|
||||
|
this.config.columns.push( |
||||
|
new DateEntityTableColumn<RuleChain>('createdTime', 'rulechain.created-time', this.datePipe, '150px'), |
||||
|
new EntityTableColumn<RuleChain>('name', 'rulechain.name'), |
||||
|
new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px', |
||||
|
entity => { |
||||
|
return checkBoxCell(entity.root); |
||||
|
}), |
||||
|
); |
||||
|
|
||||
|
this.config.addActionDescriptors.push( |
||||
|
{ |
||||
|
name: this.translate.instant('rulechain.create-new-rulechain'), |
||||
|
icon: 'insert_drive_file', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.config.table.addEntity($event) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('rulechain.import'), |
||||
|
icon: 'file_upload', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.importRuleChain($event) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.config.cellActionDescriptors.push( |
||||
|
{ |
||||
|
name: this.translate.instant('rulechain.open-rulechain'), |
||||
|
icon: 'settings_ethernet', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.openRuleChain($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('rulechain.export'), |
||||
|
icon: 'file_download', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.exportRuleChain($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('rulechain.set-root'), |
||||
|
icon: 'flag', |
||||
|
isEnabled: (ruleChain) => !ruleChain.root, |
||||
|
onAction: ($event, entity) => this.setRootRuleChain($event, entity) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title', |
||||
|
{ ruleChainName: ruleChain.name }); |
||||
|
this.config.deleteEntityContent = () => this.translate.instant('rulechain.delete-rulechain-text'); |
||||
|
this.config.deleteEntitiesTitle = count => this.translate.instant('rulechain.delete-rulechains-title', {count}); |
||||
|
this.config.deleteEntitiesContent = () => this.translate.instant('rulechain.delete-rulechains-text'); |
||||
|
|
||||
|
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink); |
||||
|
this.config.loadEntity = id => this.ruleChainService.getRuleChain(id.id); |
||||
|
this.config.saveEntity = ruleChain => this.ruleChainService.saveRuleChain(ruleChain); |
||||
|
this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); |
||||
|
this.config.onEntityAction = action => this.onRuleChainAction(action); |
||||
|
this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root; |
||||
|
this.config.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root; |
||||
|
} |
||||
|
|
||||
|
resolve(): EntityTableConfig<RuleChain> { |
||||
|
this.config.tableTitle = this.translate.instant('rulechain.rulechains'); |
||||
|
|
||||
|
return this.config; |
||||
|
} |
||||
|
|
||||
|
importRuleChain($event: Event) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
openRuleChain($event: Event, ruleChain: RuleChain) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
// this.router.navigateByUrl(`customers/${customer.id.id}/users`);
|
||||
|
} |
||||
|
|
||||
|
exportRuleChain($event: Event, ruleChain: RuleChain) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
setRootRuleChain($event: Event, ruleChain: RuleChain) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('rulechain.set-root-rulechain-title', {ruleChainName: ruleChain.name}), |
||||
|
this.translate.instant('rulechain.set-root-rulechain-text'), |
||||
|
this.translate.instant('action.no'), |
||||
|
this.translate.instant('action.yes'), |
||||
|
true |
||||
|
).subscribe((res) => { |
||||
|
if (res) { |
||||
|
this.ruleChainService.setRootRuleChain(ruleChain.id.id).subscribe( |
||||
|
() => { |
||||
|
this.config.table.updateData(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
onRuleChainAction(action: EntityAction<RuleChain>): boolean { |
||||
|
switch (action.action) { |
||||
|
case 'open': |
||||
|
this.openRuleChain(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'export': |
||||
|
this.exportRuleChain(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'setRoot': |
||||
|
this.setRootRuleChain(action.event, action.entity); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {RouterModule, Routes} from '@angular/router'; |
||||
|
|
||||
|
import {EntitiesTableComponent} from '@shared/components/entity/entities-table.component'; |
||||
|
import {Authority} from '@shared/models/authority.enum'; |
||||
|
import {RuleChainsTableConfigResolver} from '@modules/home/pages/rulechain/rulechains-table-config.resolver'; |
||||
|
import {WidgetsBundlesTableConfigResolver} from '@modules/home/pages/widget/widgets-bundles-table-config.resolver'; |
||||
|
|
||||
|
const routes: Routes = [ |
||||
|
{ |
||||
|
path: 'widgets-bundles', |
||||
|
data: { |
||||
|
breadcrumb: { |
||||
|
label: 'widgets-bundle.widgets-bundles', |
||||
|
icon: 'now_widgets' |
||||
|
} |
||||
|
}, |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '', |
||||
|
component: EntitiesTableComponent, |
||||
|
data: { |
||||
|
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN], |
||||
|
title: 'widgets-bundle.widgets-bundles' |
||||
|
}, |
||||
|
resolve: { |
||||
|
entitiesTableConfig: WidgetsBundlesTableConfigResolver |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
]; |
||||
|
|
||||
|
@NgModule({ |
||||
|
imports: [RouterModule.forChild(routes)], |
||||
|
exports: [RouterModule], |
||||
|
providers: [ |
||||
|
WidgetsBundlesTableConfigResolver |
||||
|
] |
||||
|
}) |
||||
|
export class WidgetLibraryRoutingModule { } |
||||
@ -0,0 +1,36 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {CommonModule} from '@angular/common'; |
||||
|
import {SharedModule} from '@shared/shared.module'; |
||||
|
import {WidgetsBundleComponent} from '@modules/home/pages/widget/widgets-bundle.component'; |
||||
|
import {WidgetLibraryRoutingModule} from '@modules/home/pages/widget/widget-library-routing.module'; |
||||
|
|
||||
|
@NgModule({ |
||||
|
entryComponents: [ |
||||
|
WidgetsBundleComponent |
||||
|
], |
||||
|
declarations: [ |
||||
|
WidgetsBundleComponent |
||||
|
], |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
SharedModule, |
||||
|
WidgetLibraryRoutingModule |
||||
|
] |
||||
|
}) |
||||
|
export class WidgetLibraryModule { } |
||||
@ -0,0 +1,44 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div class="tb-details-buttons"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'export')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'widgets-bundle.export' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'delete')" |
||||
|
[fxShow]="!hideDelete() && !isEdit"> |
||||
|
{{'widgets-bundle.delete' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
<div class="mat-padding" fxLayout="column"> |
||||
|
<form #entityNgForm="ngForm" [formGroup]="entityForm"> |
||||
|
<fieldset [disabled]="(isLoading$ | async) || !isEdit"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>widgets-bundle.title</mat-label> |
||||
|
<input matInput formControlName="title" required> |
||||
|
<mat-error *ngIf="entityForm.get('title').hasError('required')"> |
||||
|
{{ 'widgets-bundle.title-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</div> |
||||
@ -0,0 +1,19 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2019 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
|
||||
|
:host { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Component} from '@angular/core'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {EntityComponent} from '@shared/components/entity/entity.component'; |
||||
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
||||
|
import {WidgetsBundle} from '@shared/models/widgets-bundle.model'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-widgets-bundle', |
||||
|
templateUrl: './widgets-bundle.component.html', |
||||
|
styleUrls: ['./widgets-bundle.component.scss'] |
||||
|
}) |
||||
|
export class WidgetsBundleComponent extends EntityComponent<WidgetsBundle> { |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
hideDelete() { |
||||
|
if (this.entitiesTableConfig) { |
||||
|
return !this.entitiesTableConfig.deleteEnabled(this.entity); |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
buildForm(entity: WidgetsBundle): FormGroup { |
||||
|
return this.fb.group( |
||||
|
{ |
||||
|
title: [entity ? entity.title : '', [Validators.required]] |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
updateForm(entity: WidgetsBundle) { |
||||
|
this.entityForm.patchValue({title: entity.title}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,158 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Injectable} from '@angular/core'; |
||||
|
|
||||
|
import {Resolve, Router} from '@angular/router'; |
||||
|
import { |
||||
|
checkBoxCell, |
||||
|
DateEntityTableColumn, |
||||
|
EntityTableColumn, |
||||
|
EntityTableConfig |
||||
|
} from '@shared/components/entity/entities-table-config.models'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
import {DatePipe} from '@angular/common'; |
||||
|
import {EntityType, entityTypeResources, entityTypeTranslations} from '@shared/models/entity-type.models'; |
||||
|
import {EntityAction} from '@shared/components/entity/entity-component.models'; |
||||
|
import {WidgetsBundle} from '@shared/models/widgets-bundle.model'; |
||||
|
import {WidgetService} from '@app/core/http/widget.service'; |
||||
|
import {WidgetsBundleComponent} from '@modules/home/pages/widget/widgets-bundle.component'; |
||||
|
import {NULL_UUID} from '@shared/models/id/has-uuid'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {getCurrentAuthUser} from '@app/core/auth/auth.selectors'; |
||||
|
import {Authority} from '@shared/models/authority.enum'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableConfig<WidgetsBundle>> { |
||||
|
|
||||
|
private readonly config: EntityTableConfig<WidgetsBundle> = new EntityTableConfig<WidgetsBundle>(); |
||||
|
|
||||
|
constructor(private store: Store<AppState>, |
||||
|
private widgetsService: WidgetService, |
||||
|
private translate: TranslateService, |
||||
|
private datePipe: DatePipe, |
||||
|
private router: Router) { |
||||
|
|
||||
|
this.config.entityType = EntityType.WIDGETS_BUNDLE; |
||||
|
this.config.entityComponent = WidgetsBundleComponent; |
||||
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.WIDGETS_BUNDLE); |
||||
|
this.config.entityResources = entityTypeResources.get(EntityType.WIDGETS_BUNDLE); |
||||
|
|
||||
|
this.config.columns.push( |
||||
|
new DateEntityTableColumn<WidgetsBundle>('createdTime', 'widgets-bundle.created-time', this.datePipe, '150px'), |
||||
|
new EntityTableColumn<WidgetsBundle>('title', 'widgets-bundle.title'), |
||||
|
new EntityTableColumn<WidgetsBundle>('tenantId', 'widgets-bundle.system', '60px', |
||||
|
entity => { |
||||
|
return checkBoxCell(entity.tenantId.id === NULL_UUID); |
||||
|
}), |
||||
|
); |
||||
|
|
||||
|
this.config.addActionDescriptors.push( |
||||
|
{ |
||||
|
name: this.translate.instant('widgets-bundle.create-new-widgets-bundle'), |
||||
|
icon: 'insert_drive_file', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.config.table.addEntity($event) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('widgets-bundle.import'), |
||||
|
icon: 'file_upload', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event) => this.importWidgetsBundle($event) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.config.cellActionDescriptors.push( |
||||
|
{ |
||||
|
name: this.translate.instant('widgets-bundle.open-widgets-bundle'), |
||||
|
icon: 'now_widgets', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.openWidgetsBundle($event, entity) |
||||
|
}, |
||||
|
{ |
||||
|
name: this.translate.instant('widgets-bundle.export'), |
||||
|
icon: 'file_download', |
||||
|
isEnabled: () => true, |
||||
|
onAction: ($event, entity) => this.exportWidgetsBundle($event, entity) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.config.deleteEntityTitle = widgetsBundle => this.translate.instant('widgets-bundle.delete-widgets-bundle-title', |
||||
|
{ widgetsBundleTitle: widgetsBundle.title }); |
||||
|
this.config.deleteEntityContent = () => this.translate.instant('widgets-bundle.delete-widgets-bundle-text'); |
||||
|
this.config.deleteEntitiesTitle = count => this.translate.instant('widgets-bundle.delete-widgets-bundles-title', {count}); |
||||
|
this.config.deleteEntitiesContent = () => this.translate.instant('widgets-bundle.delete-widgets-bundles-text'); |
||||
|
|
||||
|
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink); |
||||
|
this.config.loadEntity = id => this.widgetsService.getWidgetsBundle(id.id); |
||||
|
this.config.saveEntity = widgetsBundle => this.widgetsService.saveWidgetsBundle(widgetsBundle); |
||||
|
this.config.deleteEntity = id => this.widgetsService.deleteWidgetsBundle(id.id); |
||||
|
this.config.onEntityAction = action => this.onWidgetsBundleAction(action); |
||||
|
} |
||||
|
|
||||
|
resolve(): EntityTableConfig<WidgetsBundle> { |
||||
|
this.config.tableTitle = this.translate.instant('widgets-bundle.widgets-bundles'); |
||||
|
const authUser = getCurrentAuthUser(this.store); |
||||
|
this.config.deleteEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); |
||||
|
this.config.entitySelectionEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); |
||||
|
this.config.detailsReadonly = (widgetsBundle) => !this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); |
||||
|
return this.config; |
||||
|
} |
||||
|
|
||||
|
isWidgetsBundleEditable(widgetsBundle: WidgetsBundle, authority: Authority): boolean { |
||||
|
if (authority === Authority.TENANT_ADMIN) { |
||||
|
return widgetsBundle && widgetsBundle.tenantId && widgetsBundle.tenantId.id !== NULL_UUID; |
||||
|
} else { |
||||
|
return authority === Authority.SYS_ADMIN; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
importWidgetsBundle($event: Event) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
openWidgetsBundle($event: Event, widgetsBundle: WidgetsBundle) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
// this.router.navigateByUrl(`customers/${customer.id.id}/users`);
|
||||
|
} |
||||
|
|
||||
|
exportWidgetsBundle($event: Event, widgetsBundle: WidgetsBundle) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
// TODO:
|
||||
|
} |
||||
|
|
||||
|
onWidgetsBundleAction(action: EntityAction<WidgetsBundle>): boolean { |
||||
|
switch (action.action) { |
||||
|
case 'open': |
||||
|
this.openWidgetsBundle(action.event, action.entity); |
||||
|
return true; |
||||
|
case 'export': |
||||
|
this.exportWidgetsBundle(action.event, action.entity); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div fxLayout="row" fxLayoutGap="12px" [fxHide]="isShareLinkLocal()"> |
||||
|
<button mat-button mat-icon-button mat-raised-button class="mat-primary" |
||||
|
shareButton="facebook" |
||||
|
title="{{ shareTitle }}" |
||||
|
description="{{ shareText }}" |
||||
|
url="{{ shareLink }}" |
||||
|
matTooltipPosition="above" |
||||
|
matTooltip="{{ 'action.share-via' | translate:{provider:'Facebook'} }}"> |
||||
|
<mat-icon svgIcon="mdi:facebook"></mat-icon> |
||||
|
</button> |
||||
|
<button mat-button mat-icon-button mat-raised-button class="mat-primary" |
||||
|
shareButton="twitter" |
||||
|
title="{{ shareTitle }}" |
||||
|
tags="{{ shareHashTags }}" |
||||
|
url="{{ shareLink }}" |
||||
|
matTooltipPosition="above" |
||||
|
matTooltip="{{ 'action.share-via' | translate:{provider:'Twitter'} }}"> |
||||
|
<mat-icon svgIcon="mdi:twitter"></mat-icon> |
||||
|
</button> |
||||
|
<button mat-button mat-icon-button mat-raised-button class="mat-primary" |
||||
|
shareButton="linkedin" |
||||
|
title="{{ shareTitle }}" |
||||
|
url="{{ shareLink }}" |
||||
|
matTooltipPosition="above" |
||||
|
matTooltip="{{ 'action.share-via' | translate:{provider:'Linkedin'} }}"> |
||||
|
<mat-icon svgIcon="mdi:linkedin"></mat-icon> |
||||
|
</button> |
||||
|
<button mat-button mat-icon-button mat-raised-button class="mat-primary" |
||||
|
shareButton="reddit" |
||||
|
title="{{ shareTitle }}" |
||||
|
url="{{ shareLink }}" |
||||
|
matTooltipPosition="above" |
||||
|
matTooltip="{{ 'action.share-via' | translate:{provider:'Reddit'} }}"> |
||||
|
<mat-icon svgIcon="mdi:reddit"></mat-icon> |
||||
|
</button> |
||||
|
</div> |
||||
@ -0,0 +1,61 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; |
||||
|
import { User } from '@shared/models/user.model'; |
||||
|
import { Authority } from '@shared/models/authority.enum'; |
||||
|
import { select, Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { selectAuthUser, selectUserDetails } from '@core/auth/auth.selectors'; |
||||
|
import { map } from 'rxjs/operators'; |
||||
|
import { AuthService } from '@core/auth/auth.service'; |
||||
|
import { Router } from '@angular/router'; |
||||
|
import {isLocalUrl} from '@core/utils'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-social-share-panel', |
||||
|
templateUrl: './socialshare-panel.component.html', |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class SocialSharePanelComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
shareTitle: string; |
||||
|
|
||||
|
@Input() |
||||
|
shareText: string; |
||||
|
|
||||
|
@Input() |
||||
|
shareLink: string; |
||||
|
|
||||
|
@Input() |
||||
|
shareHashTags: string; |
||||
|
|
||||
|
constructor() { |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
} |
||||
|
|
||||
|
isShareLinkLocal(): boolean { |
||||
|
if (this.shareLink && this.shareLink.length > 0) { |
||||
|
return isLocalUrl(this.shareLink); |
||||
|
} else { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue