Skip to content

Commit

Permalink
feat: add format verification for open project and import view #1538
Browse files Browse the repository at this point in the history
  • Loading branch information
unocelli committed Dec 15, 2024
1 parent ebf2c73 commit 40587cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
50 changes: 43 additions & 7 deletions client/src/app/_services/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,10 @@ export class ProjectService {
}

private notifyError(msgCode: string) {
this.translateService.get(msgCode).subscribe((txt: string) => { msgCode = txt; });
const msg = this.translateService.instant(msgCode);
if (msgCode) {
console.error(`FUXA Error: ${msgCode}`);
this.toastr.error(msgCode, '', {
console.error(`FUXA Error: ${msg}`);
this.toastr.error(msg, '', {
timeOut: 3000,
closeButton: true,
disableTimeOut: true
Expand Down Expand Up @@ -875,11 +875,47 @@ export class ProjectService {
* @param prj project data to save
*/
setProject(prj: ProjectData, skipNotification = false) {
this.projectData = prj;
if (this.appService.isClientApp) {
this.projectData = ResourceStorageService.defileProject(prj);
if (this.verifyProject(prj)) {
this.projectData = prj;
if (this.appService.isClientApp) {
this.projectData = ResourceStorageService.defileProject(prj);
}
this.save(skipNotification);
}
}

verifyProject(prj: ProjectData): boolean {
let result = true;
if (Utils.isNullOrUndefined(prj.version)) {
result = false;
} else if (Utils.isNullOrUndefined(prj.hmi)) {
result = false;
} else if (Utils.isNullOrUndefined(prj.devices)) {
result = false;
}
if (!result) {
this.notifyError('msg.project-format-error');
}
this.save(skipNotification);
return result;
}

verifyView(view: View): boolean {
let result = true;
if (Utils.isNullOrUndefined(view.svgcontent)) {
result = false;
} else if (Utils.isNullOrUndefined(view.id)) {
result = false;
} else if (Utils.isNullOrUndefined(view.profile)) {
result = false;
} else if (Utils.isNullOrUndefined(view.type)) {
result = false;
} else if (Utils.isNullOrUndefined(view.items)) {
result = false;
}
if (!result) {
this.notifyError('msg.view-format-error');
}
return result;
}

setNewProject() {
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ export class EditorComponent implements OnInit, AfterViewInit, OnDestroy {
let reader = new FileReader();
reader.onload = (data) => {
let view = JSON.parse(reader.result.toString());
if (view) {
if (this.projectService.verifyView(view)) {
let idx = 1;
let startname = view.name;
let existView = null;
Expand Down
1 change: 1 addition & 0 deletions client/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@
"msg.project-save-success": "Project save successful!",
"msg.project-save-error": "Project save failed!",
"msg.project-format-error": "Project wrong format!",
"msg.view-format-error": "View wrong format!",
"msg.project-save-unauthorized": "Project save failed! Unauthorized!",
"msg.project-save-ask": "Do you want to leave the project?",
"msg.login-username-required": "Enter a username",
Expand Down

0 comments on commit 40587cd

Please sign in to comment.