lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/viewDiff.min.js
2019-08-13 11:28:19 +02:00

1 line
3.4 KiB
JavaScript

(function(){angular.module("llngConfDiff",["ui.tree","ui.bootstrap","llApp","ngCookies"],function(t){return t.digestTtl(15)}).controller("DiffCtrl",["$scope","$http","$q","$translator","$location",function(p,o,l,r,i){var n,u,c,t,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 r.translateField(t,"title")},p.translateP=r.translateP,p.translate=r.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,p.init(),p.showM=!1},u=function(n,a){var r;return r=l.defer(),null==p.cfg[n]||p.cfg[n]!==a?o.get(""+confPrefix+a).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 "+a+" loaded"),r.resolve("OK")):r.reject(t)},function(t){return console.log(t),r.reject("NOK")}):r.resolve(),r.promise},c=function(){return p.message=null,p.currentNode=null,l.defer(),o.get(scriptname+"view/diff/"+p.cfg[0].cfgNum+"/"+p.cfg[1].cfgNum).then(function(t){var e;return[],e=s(t.data[0],t.data[1]),p.data=n(e),p.message="",p.waiting=!1},function(t){return p.message=p.translate("error")+" : "+t.statusLine})},s=function(t,e,n){var a,r,o,l;for(a in null==n&&(n=!0),r=[],t)l=t[a],o=n?{title:p.translate(a),id:a}:{title:a},a.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)||(null!=l&&"object"==typeof l?"array"===l.constructor?(o.oldvalue=l,o.newvalue=e[a]):"object"==typeof e[a]?o.nodes=s(t[a],e[a],!1):o.oldnodes=f(l,"old"):(o.oldvalue=l,o.newvalue=e[a]),r.push(o));for(a in e)l=e[a],a.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)||null!=t[a]||(o=n?{title:p.translate(a),id:a}:{title:a},null!=l&&"object"==typeof l?"array"===l.constructor?o.newvalue=l:(console.log("Iteration"),o.newnodes=f(l,"new")):o.newvalue=l,r.push(o));return r},f=function(t,e){var n,a,r,o;for(n in a=[],t)r={title:n},"object"==typeof(o=t[n])?"array"===o.constructor?r[e+"value"]=o:r[e+"nodes"]=f(t[n],e):r[e+"value"]=o,a.push(r);return a},h=[],n=function(t){var e,n,a,r,o,l,i,u,c,s,f,g,d;if(null==h)return t;for(d=[],r=0,l=t.length;r<l;r++){for(e=t[r],f=d,o=0,i=(g=null!=h[e.id]?h[e.id].split("/"):"").length;o<i;o++)if(0<(s=g[o]).length)if(f.length){for(n=-1,a=c=0,u=f.length;c<u;a=++c)f[a].id===s&&(n=a);f=-1!==n?f[n].nodes:(f.push({id:s,title:p.translate(s),nodes:[]}),f[f.length-1].nodes)}else f.push({id:s,title:p.translate(s),nodes:[]}),f=f[0].nodes;f.push(e)}return d},p.newDiff=function(){return i.path("/"+p.cfg[0].cfgNum+"/"+p.cfg[1].cfgNum)},t=function(t,e,n){var a;return null===(a=e.match(new RegExp("#!?/(latest|[0-9]+)(?:/(latest|[0-9]+))?$")))?i.path("/latest"):(p.waiting=!0,l.all([r.init(p.lang),o.get(staticPrefix+"reverseTree.json").then(function(t){return h=t.data,console.log("Structure loaded")}),u(0,a[1]),null!=a[2]?u(1,a[2]):void 0]).then(function(){return null!=a[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},p.$on("$locationChangeSuccess",t)}])}).call(this);