UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

2 lines (1 loc) • 10.8 kB
import{b as X}from"./chunk-L6O2DL5Y.js";import{n as j}from"./chunk-OHFVMRCL.js";import{A as G,c as B,d as v,e as P,f as V,g as O,j as z,m as R,p as W,q as N,z as D}from"./chunk-MMYB2ZMV.js";import{e as L}from"./chunk-QY7HUYL5.js";import{c as Q}from"./chunk-7LZPZXYJ.js";import{b as J}from"./chunk-3P637DAY.js";import{h as q,j as T,k as K}from"./chunk-SXUVUFAV.js";import{l as M}from"./chunk-R3JWGCC5.js";import{a as H,b as A}from"./chunk-KPKQNEWS.js";import{$a as i,Ac as s,Bc as l,Hb as _,Ib as f,Nb as h,Ob as n,Pb as o,Qb as d,Ub as k,Xb as b,Yb as m,bd as I,h as y,jc as p,kc as c,la as g,lb as E,lc as w,ra as C,sa as x,w as S,wc as $,xc as F}from"./chunk-QSPBB6EE.js";var U=(t,u)=>({"is-valid":t,"is-invalid":u}),Z=t=>({"button-loading":t});function ee(t,u){if(t&1){let e=k();n(0,"div",2),d(1,"img",3),n(2,"h3",4),p(3),s(4,"translate"),o(),n(5,"button",5),b("click",function(){C(e);let a=m();return x(a.onClickGettingStarted())}),p(6),s(7,"translate"),o(),n(8,"small",6)(9,"a",7),b("click",function(){C(e);let a=m();return x(a.onClickRestoreBackup())}),p(10),s(11,"translate"),o()()()}t&2&&(i(3),c(l(4,3,"setup.welcome_to_homebridge")),i(3),w(" ",l(7,5,"setup.button_get_started")," "),i(4),c(l(11,7,"setup_wizard_message_restore")))}function te(t,u){if(t&1){let e=k();n(0,"div",2),d(1,"img",8),n(2,"h3",4),p(3),s(4,"translate"),o(),n(5,"div",9)(6,"p"),p(7),s(8,"translate"),o(),n(9,"form",10),b("ngSubmit",function(){C(e);let a=m();return x(a.createFirstUser())}),n(10,"div",11)(11,"span",12),d(12,"i",13),o(),d(13,"input",14),s(14,"translate"),o(),n(15,"div",11)(16,"span",12),d(17,"i",15),o(),d(18,"input",16),s(19,"translate"),o(),n(20,"div",17)(21,"span",12),d(22,"i",15),o(),d(23,"input",18),s(24,"translate"),o(),n(25,"div",19)(26,"button",20),p(27),s(28,"translate"),d(29,"i",21),o()()()()()}if(t&2){let e=m();i(3),c(l(4,15,"setup.create_account")),i(4),c(l(8,17,"setup.create_account_reason")),i(2),h("formGroup",e.createUserForm),i(4),h("placeholder",l(14,19,"users.label_username"))("readonly",e.loading)("ngClass",F(27,U,e.createUserForm.controls.username.dirty&&e.createUserForm.controls.username.valid,e.createUserForm.controls.username.dirty&&e.createUserForm.controls.username.invalid)),i(5),h("placeholder",l(19,21,"users.label_password"))("readonly",e.loading)("ngClass",F(30,U,e.createUserForm.controls.password.dirty&&e.createUserForm.controls.password.valid,e.createUserForm.controls.password.dirty&&e.createUserForm.controls.password.errors)),i(5),h("placeholder",l(24,23,"users.label_confirm_password"))("readonly",e.loading)("ngClass",F(33,U,e.createUserForm.controls.passwordConfirm.dirty&&e.createUserForm.controls.passwordConfirm.valid,e.createUserForm.controls.passwordConfirm.dirty&&e.createUserForm.controls.passwordConfirm.errors)),i(3),h("disabled",e.createUserForm.invalid||e.loading)("ngClass",$(36,Z,e.loading)),i(),w(" ",l(28,25,"setup.create_account")," ")}}function ie(t,u){t&1&&(n(0,"span"),d(1,"i",26),p(2),s(3,"translate"),o()),t&2&&(i(2),w(" ",l(3,1,"backup.label_uploading")," "))}function ne(t,u){t&1&&(p(0),s(1,"translate")),t&2&&w(" ",l(1,1,"backup.button_restore_backup")," ")}function oe(t,u){if(t&1){let e=k();n(0,"div",2),d(1,"img",8),n(2,"h3",4),p(3),s(4,"translate"),o(),n(5,"p"),p(6),s(7,"translate"),o(),n(8,"input",22),b("change",function(a){C(e);let Y=m();return x(Y.handleRestoreFileInput(a.target.files))}),o(),n(9,"div",23)(10,"button",24),b("click",function(){C(e);let a=m();return x(a.onClickCancelRestore())}),p(11),s(12,"translate"),o(),n(13,"button",25),b("click",function(){C(e);let a=m();return x(a.onRestoreBackupClick())}),_(14,ie,4,3,"span"),_(15,ne,2,3),o()()()}if(t&2){let e=m();i(3),c(l(4,7,"form.button_restore")),i(3),c(l(7,9,"backup.restore_help_one")),i(4),h("disabled",e.restoreUploading),i(),w(" ",l(12,11,"form.button_cancel")," "),i(2),h("disabled",e.restoreUploading||!e.selectedFile),i(),f(e.restoreUploading?14:-1),i(),f(e.restoreUploading?-1:15)}}function re(t,u){t&1&&(n(0,"div",2),d(1,"img",8),n(2,"h3",4),p(3),s(4,"translate"),o(),n(5,"h1"),d(6,"i",26),o()()),t&2&&(i(3),c(l(4,1,"restart.title_restart")))}function ae(t,u){t&1&&(n(0,"div",2),d(1,"img",8),n(2,"h3",27),p(3),s(4,"translate"),o(),n(5,"p",28),p(6),s(7,"translate"),o(),n(8,"a",29),p(9),s(10,"translate"),o()()),t&2&&(i(3),c(l(4,3,"setup_wizard_message_complete_title")),i(3),c(l(7,5,"setup_wizard_message_complete_message")),i(3),c(l(10,7,"setup.open_dashboard")))}var Se=(()=>{class t{$api=g(K);$auth=g(Q);$modal=g(j);$settings=g(J);$title=g(M);$toastr=g(q);$translate=g(H);previousTitle;step="welcome";createUserForm=new O({username:new z("",[v.required]),password:new z("",[v.compose([v.required,v.minLength(4)])]),passwordConfirm:new z("",[v.required])},this.matchPassword);loading=!1;selectedFile;restoreUploading=!1;constructor(){}ngOnInit(){this.previousTitle=this.$title.getTitle(),this.$title.setTitle("Setup Homebridge")}matchPassword(e){let r=e.get("password").value,a=e.get("passwordConfirm").value;if(r!==a)e.get("passwordConfirm").setErrors({matchPassword:!0});else return null}ngOnDestroy(){this.$title.setTitle(this.previousTitle)}onClickGettingStarted(){this.step="create-account"}onClickRestoreBackup(){this.step="restore-backup"}onClickCancelRestore(){this.selectedFile=null,this.step="welcome"}createFirstUser(){this.loading=!0;let e=this.createUserForm.getRawValue();e.name=e.username,this.$api.post("/setup-wizard/create-first-user",e).subscribe({next:()=>y(this,null,function*(){this.$settings.env.setupWizardComplete=!0,yield this.$auth.login({username:e.username,password:e.password}),this.step="setup-complete"}),error:r=>{this.loading=!1,console.error(r),this.$toastr.error(r.error.message||this.$translate.instant("users.toast_failed_to_add_user"),this.$translate.instant("toast.title_error"))}})}handleRestoreFileInput(e){e.length?this.selectedFile=e[0]:delete this.selectedFile}onRestoreBackupClick(){this.restoreUploading=!0,this.uploadHomebridgeArchive()}uploadHomebridgeArchive(){return y(this,null,function*(){try{let e=yield S(this.$api.get("/setup-wizard/get-setup-wizard-token"));window.localStorage.setItem(T.jwt.tokenKey,e.access_token),this.$auth.token=e.access_token;let r=new FormData;r.append("restoreArchive",this.selectedFile,this.selectedFile.name),yield S(this.$api.post("/backup/restore",r)),this.openRestoreModal(),this.restoreUploading=!1}catch(e){this.restoreUploading=!1,console.error(e),this.$toastr.error(e.error.message||this.$translate.instant("users.toast_failed_to_add_user"),this.$translate.instant("toast.title_error"))}})}openRestoreModal(){let e=this.$modal.open(X,{size:"lg",backdrop:"static"});e.componentInstance.setupWizardRestore=!0,e.result.then(r=>{r===!0&&this.waitForHomebridgeToRestart()})}waitForHomebridgeToRestart(){return y(this,null,function*(){this.step="restarting",window.localStorage.removeItem(T.jwt.tokenKey),this.$auth.token=null,yield new Promise(r=>setTimeout(r,15e3));let e=setInterval(()=>y(this,null,function*(){try{yield S(this.$api.get("/auth/settings")),clearInterval(e),location.reload()}catch{}}),1e3)})}static \u0275fac=function(r){return new(r||t)};static \u0275cmp=E({type:t,selectors:[["ng-component"]],decls:7,vars:5,consts:[[1,"setup-container","d-flex","align-items-center","justify-content-center"],[1,"w-100","setup-card","d-flex","py-5"],[1,"w-100","d-flex","flex-column","align-items-center"],["src","/assets/homebridge-color-round.svg","alt","hb logo",1,"homebridge-logo","mx-auto"],[1,"pt-4","pb-3","text-center"],["type","button",1,"btn","btn-lg","btn-primary",3,"click"],[1,"mt-3"],["href","javascript:void(0)",1,"grey-text",3,"click"],["src","/assets/homebridge-color-round.svg","alt","hb logo",1,"homebridge-logo","homebridge-logo-small","mx-auto"],[1,"w-100"],["novalidate","",3,"ngSubmit","formGroup"],[1,"md-form","input-group","mb-3"],[1,"input-group-text","custom-input"],[1,"fas","fa-fw","fa-user","prefix","grey-text"],["formControlName","username","type","text","id","form-username","autocomplete","username","autocapitalize","none","tabindex","1",1,"form-control","py-2",3,"placeholder","readonly","ngClass"],[1,"fas","fa-fw","fa-lock","prefix","grey-text"],["formControlName","password","type","password","id","form-pass","autocomplete","new-password","tabindex","2",1,"form-control","py-2",3,"placeholder","readonly","ngClass"],[1,"md-form","input-group","mb-4"],["formControlName","passwordConfirm","type","password","id","form-pass-confirm","autocomplete","new-password","tabindex","2",1,"form-control","py-2",3,"placeholder","readonly","ngClass"],[1,"w-100","text-center"],["type","submit",1,"btn","btn-primary",3,"disabled","ngClass"],[1,"button-loading-overlay","fas","fa-fw","fa-spinner","fa-pulse"],["type","file","id","restoreFileUpload","accept","application/gzip, .gz",1,"form-control",3,"change"],[1,"mt-3","w-100","d-flex","justify-content-between"],["type","button",1,"btn","btn-elegant","ms-0",3,"click","disabled"],["type","button",1,"btn","btn-primary","me-0",3,"click","disabled"],[1,"fas","fa-fw","fa-spinner","fa-pulse"],[1,"pt-4","pb-3"],[1,"text-center"],["routerLink","/",1,"btn","btn-lg","btn-primary","mt-3"]],template:function(r,a){r&1&&(n(0,"div",0)(1,"div",1),_(2,ee,12,9,"div",2),_(3,te,30,38,"div",2),_(4,oe,16,13,"div",2),_(5,re,7,3,"div",2),_(6,ae,11,9,"div",2),o()()),r&2&&(i(2),f(a.step==="welcome"?2:-1),i(),f(a.step==="create-account"?3:-1),i(),f(a.step==="restore-backup"?4:-1),i(),f(a.step==="restarting"?5:-1),i(),f(a.step==="setup-complete"?6:-1))},dependencies:[D,R,B,P,V,G,W,N,I,L,A],styles:[".setup-container[_ngcontent-%COMP%]{background-size:cover;z-index:-1;padding-top:1em;padding-bottom:1em}@media screen and (min-height: 500px) and (min-width: 600px){.setup-container[_ngcontent-%COMP%]{padding-top:4em}}.setup-card[_ngcontent-%COMP%]{max-width:600px;border-radius:15px;background-color:#fff;padding-right:25px;padding-left:25px}.setup-card[_ngcontent-%COMP%] .form-control[_ngcontent-%COMP%]:focus{background-color:inherit!important}@media screen and (max-width: 600px){.setup-card[_ngcontent-%COMP%]{margin-left:1em;margin-right:1em}} body.dark-mode .setup-card{background-color:#2b2b2b;color:#fff}.homebridge-logo[_ngcontent-%COMP%]{margin-right:10px;height:200px}@media screen and (max-height: 500px){.homebridge-logo[_ngcontent-%COMP%]{height:100px}}@media screen and (max-width: 600px){.homebridge-logo[_ngcontent-%COMP%]{height:100px}}.homebridge-logo-small[_ngcontent-%COMP%]{height:50px}.button-loading[_ngcontent-%COMP%]{position:relative;color:#0000}.button-loading[_ngcontent-%COMP%] .button-loading-overlay[_ngcontent-%COMP%]{display:block;color:#fff}.button-loading-overlay[_ngcontent-%COMP%]{display:none;position:absolute;top:9px;left:0;right:0}small[_ngcontent-%COMP%] a[_ngcontent-%COMP%]:hover{text-decoration:underline}"]})}return t})();export{Se as a};