diff --git a/src/app/providers/mikrowizard/data.ts b/src/app/providers/mikrowizard/data.ts index 13ef962..f7fa80a 100644 --- a/src/app/providers/mikrowizard/data.ts +++ b/src/app/providers/mikrowizard/data.ts @@ -396,23 +396,22 @@ export class dataProvider { return this.MikroWizardRPC.sendJsonRequest("/api/firmware/get_firms", data); } - get_backups(devid:Number=0,page:Number,size:Number,search:any) { - var data = { - 'devid':devid, - 'page':page, - 'size':size, - 'search':search - } + get_backups(data:any) { return this.MikroWizardRPC.sendJsonRequest("/api/backup/list", data); } - get_backup(id:number){ var data = { 'id':id } return this.MikroWizardRPC.sendJsonRequest("/api/backup/get", data); } + restore_backup(id:number){ + var data = { + 'backupid':id + } + return this.MikroWizardRPC.sendJsonRequest("/api/backup/restore", data); + } get_downloadable_firms() { diff --git a/src/app/providers/mikrowizard/provider.ts b/src/app/providers/mikrowizard/provider.ts index 73bce74..a4c03ae 100644 --- a/src/app/providers/mikrowizard/provider.ts +++ b/src/app/providers/mikrowizard/provider.ts @@ -189,8 +189,6 @@ export class MikroWizardProvider { return Promise.resolve(); } - - public getUserContext(context: any) { localStorage.setItem("user_context", JSON.stringify(context)); diff --git a/src/app/views/auth_log/auth.module.ts b/src/app/views/auth_log/auth.module.ts index a9f497c..cc248dd 100644 --- a/src/app/views/auth_log/auth.module.ts +++ b/src/app/views/auth_log/auth.module.ts @@ -12,7 +12,6 @@ import { AuthRoutingModule } from './auth-routing.module'; import { AuthComponent } from './auth.component'; import { GuiGridModule } from '@generic-ui/ngx-grid'; -import { faCoffee } from '@fortawesome/free-solid-svg-icons'; import { FormsModule } from '@angular/forms'; import {MatDatepickerModule} from '@angular/material/datepicker'; diff --git a/src/app/views/backups/backups.component.html b/src/app/views/backups/backups.component.html index 56fbbc7..4ab0f93 100644 --- a/src/app/views/backups/backups.component.html +++ b/src/app/views/backups/backups.component.html @@ -1,13 +1,62 @@ - Backups + + + + Backups Filtered Result For Device ID {{devid}} + + + + + +
+ {{item.id}}:{{item.devname}} {{item.createdC}} X +
+
+
+ + + +
+
+ + + +
+
- Filtered Result For Device ID {{devid}} - - + +
+ + + Start date + + + + + + End date + + + + + + Config search + + + +
+
+ {{value}} @@ -40,8 +89,10 @@ - + @@ -50,19 +101,94 @@
- +
Please Confirm Action
-
+    
     
+ + + +
+ + +
+
+ + + + +
Comparing Configs
+ +
+ + + +
+
+ +
+ +
+ Comparing {{compareitems[0].id}}:{{compareitems[0].devname}} + {{compareitems[0].createdC}} With + {{compareitems[1].id}}:{{compareitems[1].devname}} + {{compareitems[1].createdC}} +
+ + +
- -
\ No newline at end of file + + + + +
Please Confirm Action
+ +
+ + restore backup ? + + Are you sure that You want to Restore this configuration on + device?
+
+

+ All Current device configuration will be reset:

+ * All state data/history on router will be reset
+ * All other local users on router will be deleted
+ * After restore the password of the local user will be same as configured in MikroWizard
+

+
+
+ + + + +
+ + \ No newline at end of file diff --git a/src/app/views/backups/backups.component.scss b/src/app/views/backups/backups.component.scss index e69de29..43d1b21 100644 --- a/src/app/views/backups/backups.component.scss +++ b/src/app/views/backups/backups.component.scss @@ -0,0 +1,4 @@ +@import 'ngx-diff/styles/default-theme'; +::ng-deep .modal-xl { + --cui-modal-width: 90vw!important; +} \ No newline at end of file diff --git a/src/app/views/backups/backups.component.ts b/src/app/views/backups/backups.component.ts index ff8ed52..a603e4f 100644 --- a/src/app/views/backups/backups.component.ts +++ b/src/app/views/backups/backups.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, QueryList, ViewChildren } from "@angular/core"; import { dataProvider } from "../../providers/mikrowizard/data"; import { Router, ActivatedRoute } from "@angular/router"; import { loginChecker } from "../../providers/login_checker"; @@ -14,23 +14,12 @@ import { GuiRowSelectionType, } from "@generic-ui/ngx-grid"; import { formatInTimeZone } from "date-fns-tz"; - -interface IUser { - name: string; - state: string; - registered: string; - country: string; - usage: number; - period: string; - payment: string; - activity: string; - avatar: string; - status: string; - color: string; -} +import { ToasterComponent } from "@coreui/angular"; +import { AppToastComponent } from "../toast-simple/toast.component"; @Component({ templateUrl: "backups.component.html", + styleUrls: ["backups.component.scss"], }) export class BackupsComponent implements OnInit { public uid: number; @@ -39,7 +28,13 @@ export class BackupsComponent implements OnInit { public filterText: string; public filters: any = {}; public codeForHighlightAuto: string = ""; - + public ispro: boolean = false; + public ConfirmModalVisible: boolean = false; + public CompareModalVisible: boolean = false; + public compareitems:any=[]; + public comparecontents:any=[]; + public compare_type="unified"; + public copy_msg:boolean=false; constructor( private data_provider: dataProvider, private router: Router, @@ -56,6 +51,8 @@ export class BackupsComponent implements OnInit { _self.uid = res.uid; _self.uname = res.name; _self.tz = res.tz; + _self.ispro = res['ISPRO'] + const userId = _self.uid; if (res.role != "admin") { @@ -69,6 +66,7 @@ export class BackupsComponent implements OnInit { return value !== undefined && value !== null && value !== ""; } } + @ViewChildren(ToasterComponent) viewChildren!: QueryList; public source: Array = []; public columns: Array = []; @@ -77,7 +75,8 @@ export class BackupsComponent implements OnInit { public Selectedrows: any; public BakcupModalVisible: boolean = false; public devid: number = 0; - + public filters_visible: boolean = false; + public currentBackup:any=false; public sorting = { enabled: true, multiSorting: true, @@ -94,6 +93,14 @@ export class BackupsComponent implements OnInit { display: GuiPagingDisplay.ADVANCED, }; + toasterForm = { + autohide: true, + delay: 3000, + position: "fixed", + fade: true, + closeButton: true, + }; + public columnMenu: GuiColumnMenu = { enabled: true, sort: true, @@ -115,25 +122,124 @@ export class BackupsComponent implements OnInit { ngOnInit(): void { this.devid = Number(this.route.snapshot.paramMap.get("devid")); + if (this.devid > 0) { + this.filters["devid"] = this.devid; + } this.initGridTable(); } logger(item: any) { console.dir(item); } + switch_compare_type(){ + if(this.compare_type=='unified') + this.compare_type='sided' + else + this.compare_type='unified' + } + copy_this() { + //show text copy to clipboard for 3 seconds + this.copy_msg = true; + setTimeout(() => { + this.copy_msg = false; + }, 1000); + } + + show_toast(title: string, body: string, color: string) { + const { ...props } = { ...this.toasterForm, color, title, body }; + const componentRef = this.viewChildren.first.addToast( + AppToastComponent, + props, + {} + ); + componentRef.instance["closeButton"] = props.closeButton; + } - ShowBackup(id: number) { - this.BakcupModalVisible = true; + ShowBackup(backup: any) { + var _self=this; this.loading = true; - this.data_provider.get_backup(id).then((res) => { - this.codeForHighlightAuto = res.content; - this.loading = false; + this.currentBackup = backup; + this.data_provider.get_backup(backup.id).then((res) => { + if('content' in res){ + _self.codeForHighlightAuto = res.content; + _self.loading = false; + _self.BakcupModalVisible = true; + } + else{ + this.show_toast('Error', 'Error loading backup file', 'danger') + } }); } + toggleCollapse(): void { + this.filters_visible = !this.filters_visible; + } + restore_backup(apply:boolean=false){ + var _slef=this; + if (!apply){ + this.ConfirmModalVisible = true; + return; + } + if (!this.currentBackup) + return; + if(apply){ + _slef.ConfirmModalVisible = false; + _slef.BakcupModalVisible = true; + this.show_toast('Success', 'Backup restored successfully', 'success') + this.show_toast('Info', 'Wait for the router to reboot and apply config', 'info') + this.data_provider.restore_backup(this.currentBackup.id).then((res) => { + if ('status' in res){ + if(res['status']=='success'){ + this.show_toast('Success', 'Backup restored successfully', 'success') + this.show_toast('Info', 'Wait for the router to reboot and apply config', 'info') + } + else + this.show_toast('Error', 'Error restoring backup', 'danger') + } + }); + } + } + start_compare(){ + var _self=this; + this.comparecontents=[] + this.compareitems.forEach((element:any) => { + _self.data_provider.get_backup(element.id).then((res) => { + if('content' in res){ + _self.comparecontents.push(res.content); + } + if(_self.comparecontents.length==_self.compareitems.length) + _self.CompareModalVisible=true; + }); + }); + } + + add_for_compare(item:any){ + //Only two items for compare + if(this.compareitems.length<2) + this.compareitems.filter((i:any)=>{ + return i.id!=item.id; + }).length==this.compareitems.length && this.compareitems.push(item); + else{ + //remove first element and add new item + this.compareitems.shift(); + this.compareitems.push(item); + } + } + delete_compare(i:number){ + //delete item index i from compareitems + this.compareitems.splice(i,1); + + } + reinitgrid(field: string, $event: any) { + if (field == "start") this.filters["start_time"] = $event.target.value; + else if (field == "end") this.filters["end_time"] = $event.target.value; + else if (field == "search") this.filters["search"] = $event; + this.initGridTable(); + } + initGridTable(): void { var _self=this; - this.data_provider.get_backups(this.devid, 0, 0, false).then((res) => { + this.data_provider.get_backups(this.filters).then((res) => { let index = 1; this.source = res.map((d: any) => { d.index = index; @@ -142,11 +248,9 @@ export class BackupsComponent implements OnInit { _self.tz, "yyyy-MM-dd HH:mm:ss XXX" ); - // d.created = [d.created.split("T")[0],d.created.split("T")[1].split(".")[0]].join(" ") index += 1; return d; }); - console.dir(this.source); this.loading = false; }); } diff --git a/src/app/views/backups/backups.module.ts b/src/app/views/backups/backups.module.ts index f63dacd..e1eb887 100644 --- a/src/app/views/backups/backups.module.ts +++ b/src/app/views/backups/backups.module.ts @@ -10,10 +10,19 @@ import { CollapseModule, BadgeModule, ModalModule, + FormModule, + ToastModule, } from "@coreui/angular"; import { BackupsRoutingModule } from "./backups-routing.module"; import { BackupsComponent } from "./backups.component"; import { GuiGridModule } from "@generic-ui/ngx-grid"; +import { MatDatepickerModule } from "@angular/material/datepicker"; +import { MatInputModule } from "@angular/material/input"; +import { MatFormFieldModule } from "@angular/material/form-field"; +import { MatSelectModule } from "@angular/material/select"; +import { FormsModule } from "@angular/forms"; +import { UnifiedDiffComponent,SideBySideDiffComponent } from 'ngx-diff'; +import { ClipboardModule } from "@angular/cdk/clipboard"; @NgModule({ imports: [ @@ -21,6 +30,8 @@ import { GuiGridModule } from "@generic-ui/ngx-grid"; CardModule, CommonModule, GridModule, + FormModule, + FormsModule, ButtonModule, ButtonModule, GuiGridModule, @@ -30,6 +41,14 @@ import { GuiGridModule } from "@generic-ui/ngx-grid"; HighlightAuto, HighlightLineNumbers, ModalModule, + MatFormFieldModule, + MatInputModule, + MatDatepickerModule, + MatSelectModule, + UnifiedDiffComponent, + SideBySideDiffComponent, + ToastModule, + ClipboardModule ], declarations: [BackupsComponent], }) diff --git a/src/app/views/user_tasks/user_tasks.component.html b/src/app/views/user_tasks/user_tasks.component.html index 18d68c4..4592d59 100644 --- a/src/app/views/user_tasks/user_tasks.component.html +++ b/src/app/views/user_tasks/user_tasks.component.html @@ -57,7 +57,6 @@ -
Editing device {{SelectedTask['name']}}
@@ -88,7 +87,7 @@
Update Version Strategy
- +