lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/diff.min.js

1 line
3.6 KiB
JavaScript

!function(){angular.module("llngConfDiff",["ui.tree","ui.bootstrap","llApp","ngCookies"],["$rootScopeProvider",function(t){return t.digestTtl(15)}]).controller("DiffCtrl",["$scope","$http","$q","$translator","$location",function(p,a,l,o,i){var e,u,c,s,h,f;return p.links=links,p.menulinks=menulinks,p.staticPrefix=staticPrefix,p.scriptname=scriptname,p.availableLanguages=availableLanguages,p.waiting=!0,p.showM=!1,p.cfg=[],p.data={},p.currentNode=null,p.translateTitle=function(t){return o.translateField(t,"title")},p.translateP=o.translateP,p.translate=o.translate,p.toggle=function(t){return t.toggle()},p.stoggle=function(t,e){return p.currentNode=e,t.toggle()},p.menuClick=function(t){if(t.popup)window.open(t.popup);else switch(t.action||(t.action=t.title),typeof t.action){case"function":t.action(p.currentNode,p);break;case"string":p[t.action]();break;default:console.log(typeof t.action)}return p.showM=!1},p.getLanguage=function(t){return p.lang=t,c(),p.showM=!1},u=function(n,r){var o=l.defer();return null==p.cfg[n]||p.cfg[n]!==r?a.get(""+confPrefix+r).then(function(t){var e;return t&&t.data?(p.cfg[n]=t.data,e=new Date(1e3*t.data.cfgDate),p.cfg[n].date=e.toLocaleString(),console.log("Metadatas of cfg "+r+" loaded"),o.resolve("OK")):o.reject(t)},function(t){return console.log(t),o.reject("NOK")}):o.resolve(),o.promise},c=function(){return p.message=null,p.currentNode=null,l.all([o.init(p.lang),a.get(staticPrefix+"reverseTree.json").then(function(t){t.data;return console.log("Structure loaded")})]).then(function(){l.defer();return a.get(scriptname+"diff/"+p.cfg[0].cfgNum+"/"+p.cfg[1].cfgNum).then(function(t){return t=s(t.data[0],t.data[1]),p.data=e(t),p.message="",p.waiting=!1},function(t){return p.message=p.translate("error")+" : "+t.statusLine})}),p.activeModule="conf",p.myStyle={color:"#ffb84d"},p.bannerStyle={"background-color":""+window.bannerColor}},s=function(t,e,n){var r,o,a,l;for(r in null==n&&(n=!0),o=[],t)l=t[r],a=n?{title:p.translate(r),id:r}:{title:r},r.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)||(null==l||"object"!=typeof l||"array"===l.constructor?(a.oldvalue=l,a.newvalue=e[r]):"object"==typeof e[r]?a.nodes=s(t[r],e[r],!1):a.oldnodes=f(l,"old"),o.push(a));for(r in e)l=e[r],r.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)||null!=t[r]||(a=n?{title:p.translate(r),id:r}:{title:r},null==l||"object"!=typeof l||"array"===l.constructor?a.newvalue=l:(console.log("Iteration"),a.newnodes=f(l,"new")),o.push(a));return o},f=function(t,e){var n,r,o,a=[];for(n in t)r={title:n},"object"!=typeof(o=t[n])||"array"===o.constructor?r[e+"value"]=o:r[e+"nodes"]=f(t[n],e),a.push(r);return a},h=[],e=function(t){var e,n,r,o,a,s,f,g,l,i,u,d,c;if(null==h)return t;for(c=[],o=0,s=t.length;o<s;o++){for(e=t[o],u=c,a=0,f=(d=null!=h[e.id]?h[e.id].split("/"):"").length;a<f;a++)if(0<(i=d[a]).length)if(u.length){for(n=-1,r=l=0,g=u.length;l<g;r=++l)u[r].id===i&&(n=r);u=-1!==n?u[n].nodes:(u.push({id:i,title:p.translate(i),nodes:[]}),u[u.length-1].nodes)}else u.push({id:i,title:p.translate(i),nodes:[]}),u=u[0].nodes;u.push(e)}return c},p.newDiff=function(){return i.path("/"+p.cfg[0].cfgNum+"/"+p.cfg[1].cfgNum)},p.$on("$locationChangeSuccess",function(t,e,n){var r=e.match(new RegExp("#!?/(latest|[0-9]+)(?:/(latest|[0-9]+))?$"));return null===r?i.path("/latest"):(p.waiting=!0,l.all([o.init(p.lang),a.get(staticPrefix+"reverseTree.json").then(function(t){return h=t.data,console.log("Structure loaded")}),u(0,r[1]),null!=r[2]?u(1,r[2]):void 0]).then(function(){return null!=r[2]?c():p.cfg[0].prev?(p.cfg[1]=p.cfg[0],u(0,p.cfg[1].prev).then(function(){return c()})):(p.data=[],p.waiting=!1)},function(){return p.message=p.translate("error"),p.waiting=!1})),!0})}])}.call(this);