2022-05-26 13:50:50 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2022 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.
|
|
|
|
|
///
|
|
|
|
|
|
2022-06-01 13:10:32 +03:00
|
|
|
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
|
2022-05-26 13:50:50 +03:00
|
|
|
import { PageComponent } from '@shared/components/page.component';
|
|
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
2022-06-01 13:10:32 +03:00
|
|
|
import {
|
|
|
|
|
EntityDataInfo,
|
|
|
|
|
SingleEntityVersionLoadRequest,
|
|
|
|
|
VersionLoadRequestType,
|
|
|
|
|
VersionLoadResult
|
|
|
|
|
} from '@shared/models/vc.models';
|
2022-05-26 13:50:50 +03:00
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import { EntitiesVersionControlService } from '@core/http/entities-version-control.service';
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2022-06-01 13:10:32 +03:00
|
|
|
import { TbPopoverComponent } from '@shared/components/popover.component';
|
|
|
|
|
import { delay } from 'rxjs/operators';
|
2022-06-02 12:32:10 +03:00
|
|
|
import { SafeHtml } from '@angular/platform-browser';
|
2022-05-26 13:50:50 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-entity-version-restore',
|
|
|
|
|
templateUrl: './entity-version-restore.component.html',
|
2022-06-02 12:32:10 +03:00
|
|
|
styleUrls: ['./version-control.scss']
|
2022-05-26 13:50:50 +03:00
|
|
|
})
|
|
|
|
|
export class EntityVersionRestoreComponent extends PageComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
branch: string;
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
versionName: string;
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
versionId: string;
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
externalEntityId: EntityId;
|
|
|
|
|
|
|
|
|
|
@Input()
|
2022-06-02 12:32:10 +03:00
|
|
|
onClose: (result: VersionLoadResult | null) => void;
|
2022-05-26 13:50:50 +03:00
|
|
|
|
2022-06-01 13:10:32 +03:00
|
|
|
@Input()
|
|
|
|
|
popoverComponent: TbPopoverComponent;
|
|
|
|
|
|
|
|
|
|
entityDataInfo: EntityDataInfo = null;
|
|
|
|
|
|
2022-05-26 13:50:50 +03:00
|
|
|
restoreFormGroup: FormGroup;
|
|
|
|
|
|
2022-06-02 12:32:10 +03:00
|
|
|
errorMessage: SafeHtml;
|
|
|
|
|
|
2022-05-26 13:50:50 +03:00
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
private entitiesVersionControlService: EntitiesVersionControlService,
|
2022-06-01 13:10:32 +03:00
|
|
|
private cd: ChangeDetectorRef,
|
2022-05-26 13:50:50 +03:00
|
|
|
private translate: TranslateService,
|
|
|
|
|
private fb: FormBuilder) {
|
|
|
|
|
super(store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.restoreFormGroup = this.fb.group({
|
2022-06-01 16:35:20 +03:00
|
|
|
loadAttributes: [true, []],
|
2022-06-02 12:32:10 +03:00
|
|
|
loadRelations: [true, []],
|
|
|
|
|
loadCredentials: [true, []]
|
2022-06-01 13:10:32 +03:00
|
|
|
});
|
|
|
|
|
this.entitiesVersionControlService.getEntityDataInfo(this.externalEntityId, this.versionId).subscribe((data) => {
|
|
|
|
|
this.entityDataInfo = data;
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
if (this.popoverComponent) {
|
|
|
|
|
this.popoverComponent.updatePosition();
|
|
|
|
|
}
|
2022-05-26 13:50:50 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancel(): void {
|
|
|
|
|
if (this.onClose) {
|
|
|
|
|
this.onClose(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore(): void {
|
|
|
|
|
const request: SingleEntityVersionLoadRequest = {
|
|
|
|
|
branch: this.branch,
|
|
|
|
|
versionId: this.versionId,
|
|
|
|
|
externalEntityId: this.externalEntityId,
|
|
|
|
|
config: {
|
2022-06-01 13:10:32 +03:00
|
|
|
loadRelations: this.entityDataInfo.hasRelations ? this.restoreFormGroup.get('loadRelations').value : false,
|
2022-06-02 12:32:10 +03:00
|
|
|
loadAttributes: this.entityDataInfo.hasAttributes ? this.restoreFormGroup.get('loadAttributes').value : false,
|
|
|
|
|
loadCredentials: this.entityDataInfo.hasCredentials ? this.restoreFormGroup.get('loadCredentials').value : false
|
2022-05-26 13:50:50 +03:00
|
|
|
},
|
|
|
|
|
type: VersionLoadRequestType.SINGLE_ENTITY
|
|
|
|
|
};
|
|
|
|
|
this.entitiesVersionControlService.loadEntitiesVersion(request).subscribe((result) => {
|
2022-06-02 12:32:10 +03:00
|
|
|
if (result.error) {
|
|
|
|
|
this.errorMessage = this.entitiesVersionControlService.entityLoadErrorToMessage(result.error);
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
if (this.popoverComponent) {
|
|
|
|
|
this.popoverComponent.updatePosition();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (this.onClose) {
|
|
|
|
|
this.onClose(result);
|
|
|
|
|
}
|
2022-05-26 13:50:50 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|