forked from yelisaveta/fortune-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortune-admin.min.js
2 lines (2 loc) · 31.7 KB
/
fortune-admin.min.js
1
2
angular.module("templates-main",["/templates/directives/faEditable.html","/templates/directives/uml/canvas.html","/templates/views/mynavbar.html","/templates/views/resources.html","/templates/views/resourcesCells.html","/templates/views/uml.html","/templates/views/umlCells.html"]),angular.module("/templates/directives/faEditable.html",[]).run(["$templateCache",function(a){a.put("/templates/directives/faEditable.html",'<section>\n <div ng-switch="schemaType">\n <div ng-switch-when="String">\n <a href="#" onaftersave="apply(value)" editable-text="value">{{value || \'Not set.\'}}</a>\n </div>\n <div ng-switch-when="Number">\n <a href="#" onaftersave="apply(value)" editable-number="value">{{value || \'Not set.\'}}</a>\n </div>\n <div ng-switch-when="Date">\n <a href="#" onaftersave="apply(value)" editable-date="value">{{value || \'Not set.\'}}</a>\n </div>\n <div ng-switch-when="Boolean">\n <a href="#" onaftersave="apply(value)" editable-checkbox="value">{{value ? \'Yep\' : \'Nope\'}}</a>\n </div>\n </div>\n</section>')}]),angular.module("/templates/directives/uml/canvas.html",[]).run(["$templateCache",function(a){a.put("/templates/directives/uml/canvas.html",'<div id="umlcanvas">\n</div>')}]),angular.module("/templates/views/mynavbar.html",[]).run(["$templateCache",function(a){a.put("/templates/views/mynavbar.html",'<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" bs-navbar>\n <div class="container-fluid">\n <div class="navbar-header">\n <a class="navbar-brand" href="#"><b>Fortune Admin</b></a>\n </div>\n <div class="collapse navbar-collapse">\n <ul class="nav navbar-nav">\n <fortune-admin-resources-cells></fortune-admin-resources-cells>\n <fortune-admin-uml-cells></fortune-admin-uml-cells>\n </ul>\n </div>\n </div>\n</nav>\n\n')}]),angular.module("/templates/views/resources.html",[]).run(["$templateCache",function(a){a.put("/templates/views/resources.html",'<section id="fortune-admin" ng-class="{wmargin: navbarEnabled}">\n <div ng-if="navbarEnabled">\n <fortune-admin-navbar></fortune-admin-navbar>\n </div>\n <h4 class="text-center">{{ parentResourceName | uppercase }} {{ parentId ? parentId + \' /\' : null}} {{plurResourceName | uppercase}}</h4>\n <table class="table table-bordered">\n <tr>\n <th ng-repeat="(name, type) in currentResource.schema | filterLinks" ng-class="{\'column-filter\': showFilter}">\n <div>\n <span>{{name}}</span>\n <span class="glyphicon glyphicon-filter" ng-show="!showFilter" ng-click="showFilter = !showFilter"></span>\n <span class="glyphicon glyphicon-remove" ng-show="showFilter" ng-click="showFilter = false; taQuery=\'\'; ResourcesCtrl.dropFilter(name, taQuery)"></span>\n </div>\n <div ng-switch="type">\n <div ng-switch-when="String" ng-show="showFilter">\n <input type="text" class="form-control" ng-model="taQuery" typeahead="item.{{name}} for item in ResourcesCtrl.getTypeaheadList($viewValue, name, type)" typeahead-on-select="ResourcesCtrl.applyFilter({item: $item, model: $model, label: $label}, name, type)">\n </div>\n <div ng-switch-when="Number" ng-show="showFilter">\n <div class="input-group">\n <span class="input-group-addon">From:</span>\n <input type="number" ng-model="Query.start" class="form-control" ng-change="ResourcesCtrl.applyFilter(Query, name, type)"/>\n </div>\n <div class="input-group">\n <span class="input-group-addon">To:</span>\n <input class="form-control" type="number" ng-model="Query.end" ng-change="ResourcesCtrl.applyFilter(Query, name, type)"/>\n </div>\n </div>\n <div ng-switch-when="Date" ng-show="showFilter">\n <div class="input-group">\n <span class="input-group-addon">From:</span>\n <input type="date" class="form-control" ng-model="Query.start" ng-change="ResourcesCtrl.applyFilter(Query, name, type)"/>\n </div>\n <div class="input-group">\n <span class="input-group-addon">To:</span>\n <input type="date" class="form-control" ng-model="Query.end" ng-change="ResourcesCtrl.applyFilter(Query, name, type)"/>\n </div>\n </div>\n <div ng-switch-when="Boolean" ng-show="showFilter">\n <div class="btn-group btn-group-sm">\n <button class="btn btn-sm" ng-class="{\'btn-default\': !Query.yep, \'btn-info\': Query.yep}" type="button" ng-click="Query.yep = true; Query.nope=false; ResourcesCtrl.applyFilter(true, name, type);">Yep</button>\n <button class="btn btn-sm" ng-class="{\'btn-default\': !Query.nope, \'btn-info\': Query.nope}" type="button" ng-click="Query.yep = false; Query.nope=true; ResourcesCtrl.applyFilter(false, name, type);">Nope</button>\n </div>\n </div>\n </div>\n </th>\n <th ng-repeat="(linkName, link) in links">{{ResourcesCtrl.resolveFieldName(linkName)}}</th>\n <th>Actions</th>\n </tr>\n <tr ng-repeat="entity in data">\n <td ng-repeat="(path, type) in currentResource.schema | filterLinks">\n <fa-editable ng-model="entity[path]" path="path" resource-name="{{plurResourceName}}" resource-id="{{entity.id}}" schema-type="type"></fa-editable>\n </td>\n <td ng-repeat="(linkName, link) in links">\n <div ng-if="ResourcesCtrl.linkToMany(linkName)">\n <a ng-href="{{ fortuneAdminRoute(\'subresource\', {parent: plurResourceName, id: entity.id, name: link.type, inverse: ResourcesCtrl.resolveInverse(linkName)}) }}">Navigate to {{link.type}}</a>\n </div>\n <div ng-if="!ResourcesCtrl.linkToMany(linkName)">\n <div ng-init="fname = ResourcesCtrl.resolveFieldName(linkName)"></div>\n <!--Initialize links if they do not come from server-->\n <div ng-init="entity.links = entity.links || {}"></div>\n <fa-ref ng-model="entity.links[fname]" ref="currentResource.schema[fname]" resource-name="{{ plurResourceName }}" resource-id="{{ entity.id }}"></fa-ref>\n </div>\n </td>\n <td>\n <button type="button" ng-click="ResourcesCtrl.deleteRow($index, entity.id)" class="btn btn-xs btn-danger">Delete</button>\n </td>\n </tr>\n </table>\n <div class="col-md-3">\n <div ng-hide="PK === \'id\'">\n <label>Enter {{ PK }} for new {{ currentResource.name }}</label>\n <input type="text" ng-model="PrimaryKey" ng-required="true" class="form-control"/>\n </div>\n <button type="button" ng-click="ResourcesCtrl.addRow(PrimaryKey)" class="btn btn-default btn-sm" ng-disabled="PK !== \'id\' && !PrimaryKey">Create new row</button>\n </div>\n</section>')}]),angular.module("/templates/views/resourcesCells.html",[]).run(["$templateCache",function(a){a.put("/templates/views/resourcesCells.html",'<li class="dropdown">\n <a href="#" class="dropdown-toggle">Resources <b class="caret"></b></a>\n <ul class="dropdown-menu">\n <li ng-repeat="service in services">\n <a ng-click="service.collapse = !service.collapse; $event.stopPropagation();">{{service.name}}</a>\n <div collapse="service.collapse">\n <div ng-repeat="resource in service.resources | orderBy:\'name\'">\n <a data-ng-href="{{ r(\'resource\', {name: resource.route }) }}">{{ resource.route }}</a>\n </div>\n </div>\n </li>\n </ul>\n</li>')}]),angular.module("/templates/views/uml.html",[]).run(["$templateCache",function(a){a.put("/templates/views/uml.html",'<section id="fortune-admin" ng-class="{wmargin: navbarEnabled}">\n <div ng-if="navbarEnabled">\n <fortune-admin-navbar></fortune-admin-navbar>\n </div>\n <section ng-if="resources.length !== 0">\n <div ng-if="render">\n <div resources-canvas resources="resources"></div>\n </div>\n </section>\n</section>')}]),angular.module("/templates/views/umlCells.html",[]).run(["$templateCache",function(a){a.put("/templates/views/umlCells.html","<li><a data-ng-href=\"{{ r('uml_diagram') }}\">UML</a></li>")}]),angular.module("fortuneAdmin",["templates-main","ui.bootstrap","xeditable","fortuneAdmin.Controllers","fortuneAdmin.Directives","fortuneAdmin.Services","fortuneAdmin.Uml"]).provider("fortuneAdmin",[function(){var a={},b=null,c={when:function(b,c,d){a[b]={url:c,params:d}},install:function(c){for(var d in a){var e=a[d],f=e.url,g=e.params;c.when(f,g)}b&&c.otherwise(b)}},d=window.CONFIG.fortuneAdmin;return{setApiHost:function(a){CONFIG.fortuneAdmin.baseEndpoint=a},setApiNamespace:function(a){CONFIG.fortuneAdmin.apiNamespace=a},html5Mode:function(a,b){CONFIG.fortuneAdmin.routing.html5Mode=!!a,CONFIG.fortuneAdmin.routing.urlPrefix=b||""},enableNavbar:function(){CONFIG.fortuneAdmin.enableNavbar=!0},mountTo:function(a,b){c.when("uml_diagram",b+"/uml",{templateUrl:d.prepareViewTemplateUrl("uml"),controller:"UmlCtrl as UmlCtrl"}),c.when("resource",b+"/:name",{templateUrl:d.prepareViewTemplateUrl("resources"),controller:"ResourcesCtrl as ResourcesCtrl",resolve:{resources:["$q","$http",function(a,b){var c=a.defer();return b.get(d.baseEndpoint+"/resources").success(function(a){c.resolve(a.resources)}),c.promise}],data:["$q","$http","$route",function(a,b,c){var e=c.current.params.name,f=a.defer();return b.get(d.getApiNamespace()+"/"+e,{params:{limit:20}}).success(function(a){f.resolve(a)}),f.promise}]}}),c.when("subresource",b+"/:parent/:id/:name/refby/:inverse",{templateUrl:d.prepareViewTemplateUrl("resources"),controller:"ResourcesCtrl as ResourcesCtrl",resolve:{resources:["$q","$http",function(a,b){var c=a.defer();return b.get(d.baseEndpoint+"/resources").success(function(a){c.resolve(a.resources)}),c.promise}],data:["$q","$http","$route",function(a,b,c){var e=a.defer(),f=c.current.params.inverse,g=c.current.params.id,h=c.current.params.name;return b.get(d.getApiNamespace()+"/"+h+"?filter["+f+"]="+g+"&limit=20").success(function(a){e.resolve(a)}),e.promise}]}}),c.install(a)},$get:function(){return{getRoute:function(b){return a[b]},replaceUrlParams:function(a,b){for(var c in b){var d=b[c];a=a.replace(":"+c,d)}return a},routeDefined:function(a){return!!this.getRoute(a)},routePath:function(a,b){var c=this.getRoute(a);return c=c?c.url:null,c&&b&&(c=this.replaceUrlParams(c,b)),CONFIG.fortuneAdmin.routing.html5Mode?c:"/#"+CONFIG.fortuneAdmin.routing.urlPrefix+c},setApiHost:function(a){CONFIG.fortuneAdmin.baseEndpoint=a},setApiNamespace:function(a){CONFIG.fortuneAdmin.apiNamespace=a},setAuthToken:function(a){CONFIG.fortuneAdmin.authToken=a}}}}}]).run(["$rootScope","$location","fortuneAdmin","editableOptions",function(a,b,c,d){var e="";a.fortuneAdminRoute=function(a,b){return e+c.routePath(a,b)},a.navbarEnabled=!!CONFIG.fortuneAdmin.enableNavbar,d.theme="bs3"}]),function(){window.CONFIG||(window.CONFIG={}),window.CONFIG.fortuneAdmin={templateDirectory:"/templates/",baseEndpoint:"",apiNamespace:"/api/v1",getApiNamespace:function(){return this.baseEndpoint+this.apiNamespace},mountPoint:"",appVersion:1,viewUrlPrefix:"/templates/views/",templateFileSuffix:".html",prepareViewTemplateUrl:function(a){return this.viewUrlPrefix+a+this.templateFileSuffix},routing:{html5Mode:!0,prefix:""},authToken:""}}(),angular.module("fortuneAdmin.Controllers",["fortuneAdmin.Services"]).filter("filterLinks",[function(){return function(a){var b={};return angular.forEach(a,function(a,c){angular.isObject(a)||(b[c]=a)}),b}}]).controller("ResourcesCtrl",["$scope","$http","$routeParams","resources","data",function(a,b,c,d,e){function f(){b.get(CONFIG.fortuneAdmin.getApiNamespace()+"/"+h,{params:a.filter}).success(function(b){console.log(b),a.data=b[h]})}var g={};angular.forEach(d,function(a){(a.name===c.name||a.route===c.name)&&(g=a)});var h=g.route;a.plurResourceName=h,a.currentResource=g,a.resources=d,a.data=e[h],a.links=e.links,a.PK=a.currentResource.modelOptions?a.currentResource.modelOptions.pk||"id":"id",a.parentResourceName=c.parent,a.parentId=c.id,this.resolveFieldName=function(a){var b=a.split(".");return b[b.length-1]},this.resolveInverse=function(a){var b=this.resolveFieldName(a),c=g.schema[b],d="";if(angular.isArray(c))d=c[0].inverse;else{if(!angular.isObject(c))throw new Error("Malformed reference");d=c.inverse}return d},this.linkToMany=function(a){var b=this.resolveFieldName(a),c=g.schema[b];return angular.isArray(c)},this.addRow=function(d){var e={};if("id"!==a.PK&&(e[a.PK]=d),c.id){var f=c.inverse;e[f]=angular.isArray(a.currentResource.schema[f])?[c.id]:c.id}var g={};g[h]=[e],b.post(CONFIG.fortuneAdmin.getApiNamespace()+"/"+h,g).success(function(b){a.data.push(b[h][0])})},this.deleteRow=function(c,d){b.delete(CONFIG.fortuneAdmin.getApiNamespace()+"/"+h+"/"+d).success(function(){a.data.splice(c,1)}).error(function(a,b){console.error(a,b)})},a.filter={},this.getTypeaheadList=function(a,c){var d={};return d["filter["+c+"][regex]"]=a,d["filter["+c+"][options"]="i",b.get(CONFIG.fortuneAdmin.getApiNamespace()+"/"+h,{params:d}).then(function(a){console.log(a.data[h]);var b=[],d=[];return angular.forEach(a.data[h],function(a){-1===d.indexOf(a[c])&&(d.push(a[c]),b.push(a))}),b})},this.applyFilter=function(b,c,d){switch(d){case"String":a.filter["filter["+c+"][regex]"]=b.model,a.filter["filter["+c+"][options]"]="i";break;case"Number":case"Date":a.filter["filter["+c+"][gte]"]=b.start,a.filter["filter["+c+"][lte]"]=b.end;break;case"Boolean":a.filter["filter["+c+"]"]=b}f()},this.dropFilter=function(b){delete a.filter["filter["+b+"][regex]"],delete a.filter["filter["+b+"][options]"],delete a.filter["filter["+b+"][gte]"],delete a.filter["filter["+b+"][lte]"],delete a.filter["filter["+b+"]"],f()}}]),angular.module("fortuneAdmin.Directives",[]).directive("fortuneAdminNavbar",[function(){return{restrict:"E",templateUrl:"/templates/views/mynavbar.html",replace:!0,transclude:!0,scope:{}}}]).directive("fortuneAdminResourcesCells",["$http","$rootScope",function(a,b){return{restrict:"E",templateUrl:"/templates/views/resourcesCells.html",replace:!0,scope:!0,link:function(c){c.r=b.fortuneAdminRoute,c.resources=[],a.get(CONFIG.fortuneAdmin.baseEndpoint+"/resources").success(function(a){c.resources=a.resources,c.services={},angular.forEach(a.resources,function(a){a.service=(a.service||"default-service").split("-").join(" "),c.services[a.service]=c.services[a.service]||{name:a.service,resources:[],collapse:!0},c.services[a.service].resources.push(a)})})}}}]).directive("fortuneAdminUmlCells",["$rootScope",function(a){return{restrict:"E",replace:!0,templateUrl:"/templates/views/umlCells.html",scope:!0,link:function(b){b.r=a.fortuneAdminRoute}}}]).controller("faEditableCtrl",["$scope","$http",function(a,b){a.apply=function(c){var d=[];d.push({op:"replace",path:"/"+a.resourceName+"/0/links/"+a.path,value:c}),b({method:"PATCH",url:CONFIG.fortuneAdmin.getApiNamespace()+"/"+a.resourceName+"/"+a.resourceId,data:d}).catch(function(a,b){console.error(a,b)})}}]).directive("faEditable",[function(){return{restrict:"E",replace:!0,scope:{value:"=ngModel",path:"=",schemaType:"=",resourceName:"@",resourceId:"@"},templateUrl:"/templates/directives/faEditable.html",controller:"faEditableCtrl"}}]).directive("faRef",["$http","$compile",function(a,b){return{restrict:"E",replace:!1,scope:{value:"=ngModel",ref:"=",resourceName:"@",resourceId:"@"},controller:"faEditableCtrl",link:function(c,d){var e,f,g=(c.path=c.ref.ref,c.resources);a.get(CONFIG.fortuneAdmin.baseEndpoint+"/resources").success(function(h){g=h.resources,angular.forEach(g,function(a){a.name===c.ref.ref&&(f=a.route,e=a)}),a.get(CONFIG.fortuneAdmin.getApiNamespace()+"/"+f).success(function(a){var g=e.modelOptions?e.modelOptions.pk||"id":"id";c.list=a[f];var h=['<a href="#" editable-select="value" ','e-ng-options="item.',g||"id"," as item.",g||"id",' for item in list" ','onaftersave="apply(value)">','{{ value || "Not set." }}',"</a>"],i=b(h.join(""))(c);d.append(i)})})}}}]),function(a){function b(a,b){a.resources=[],a.render=!1,b.get(CONFIG.fortuneAdmin.baseEndpoint+"/resources").success(function(b){a.resources=b.resources,a.render=!0})}a.module("fortuneAdmin.Uml.Controllers",[]).controller("UmlCtrl",["$scope","$http",b])}(angular),function(a){a.module("fortuneAdmin.Uml.D3",[]).factory("d3",["$q","$timeout","$rootScope",function(a,b,c){var d=a.defer();return b(function(){c.$apply(function(){d.resolve(window.d3)})}),{load:function(){return d.promise}}}])}(angular),function(a){function b(b,c){return{restrict:"A",templateUrl:"/templates/directives/uml/canvas.html",scope:{resources:"="},link:function(d,e){function g(){for(var a=c.bottomLine[0],b=0,d=0;d<c.bottomLine.length;d++)c.bottomLine[d]<a&&(a=c.bottomLine[d],b=d);return[b,a]}function h(a,b){return c.positions[a][b]}c.clear(),d.canvas={};var i={},j={},k=0,l=Math.floor(e[0].clientWidth/f.columnWidth),m={};a.forEach(d.resources,function(a){m[a.service]=m[a.service]||[],m[a.service].push(a)}),d.resources=a.copy(m),m={},a.forEach(d.resources,function(b){m=a.copy(b);var c=m[0],d=Object.keys(m[0].schema).length,e=0;a.forEach(m,function(a,b){Object.keys(a.schema).length>d&&(c=a,d=Object.keys(a.schema).length,e=b)});var f=b.splice(e,1);b=f.concat(b),a.forEach(b,function(b,c){var d=b.service||"default";i[d]=i[d]||[],i[d][c]=[],j[d]=j[d]||{},j[d][c]={name:b.name,service:b.service},b.modelOptions&&b.modelOptions.pk&&(j[d][c].pk=b.modelOptions.pk||"id"),a.forEach(b.schema,function(a,b){i[d][c].push({name:b,params:a,pk:j[d][c].pk===b})}),i[d][c].sort(function(a,b){return a.name>b.name?1:-1})})}),d.resources=i,function(){for(var b=0;l>b;b++)c.bottomLine.push(30);a.forEach(i,function(b,d){function e(a,b){var e=a.length*f.fieldHeight+f.headerHeight,h=g(),i={x:h[0]*f.columnWidth,y:h[1],height:e,column:h[0]};c.bottomLine[h[0]]+=e+f.vgap,c.positions[d]=c.positions[d]||[],c.positions[d][b]=i}a.forEach(b,function(a,b){e(a,b)});var h=c.bottomLine[0];a.forEach(c.bottomLine,function(a){a>h&&(h=a)});for(var i=c.bottomLine.length;i>=0;i--)c.bottomLine[i]=h})}();for(var n=0;n<c.bottomLine.length;n++)c.bottomLine[n]>k&&(k=c.bottomLine[n]+100);var o=d3.select(e[0]).append("svg").attr("id","mainCanvas").attr("height",k).style("width","100%"),p=o[0][0].offsetTop,q=o[0][0].clientWidth;c.setBase(p),a.forEach(i,function(b,d){var e=c.positions[d][0];e=e.y+e.height,a.forEach(c.positions[d],function(a){a.y+a.height>e&&(e=a.y+a.height)});var g=o.append("svg").attr("id",d).attr("height",e).style("width","100%"),i=g.selectAll("g").data(b).enter().append("g").attr("height",function(a){return a.length*f.fieldHeight}).attr("width",f.fieldWidth).attr("x",0).attr("y",0).attr("fill","#ffffff").append("foreignObject").attr("x",function(a,b){return h(d,b).x+f.vgap}).attr("y",function(a,b){return h(d,b).y}).attr("height",function(a){return a.length*f.fieldHeight+f.headerHeight}).attr("width",f.fieldWidth).append("xhtml:div").attr("class","resource"),k=i.append("xhtml:div").attr("class","header");k.append("xhtml:h4").attr("class","text-center").text(function(a,b){return j[d][b].name}),i.append("xhtml:div").attr("style","width: 100%").append("xhtml:div").attr("resource-class","").attr("resource",function(a,b){return'resources["'+d+'"]['+b+"]"}),a.forEach(i[0],function(a){c.add("resources",a,a.innerText)}),g.append("rect").attr("width",q-10).attr("x",5).attr("y",i[0][0].offsetTop-10-75).attr("height",e-i[0][0].offsetTop+85).attr("fill","none").attr("stroke","red"),g.append("rect").attr("width",f.fieldWidth).attr("height",f.fieldHeight).attr("x",0).attr("y",i[0][0].offsetTop-20-85).attr("fill","black"),g.append("text").attr("width",f.fieldWidth).attr("height",f.fieldHeight).attr("x",0).attr("y",i[0][0].offsetTop-20-70).attr("fill","white").text(d)}),e.removeAttr("resources-canvas"),b(e)(d)}}}function c(a){return{restrict:"A",scope:{resource:"="},link:function(b,c){{var d=b.resource.length*f.fieldHeight,e=d3.select(c[0]).append("svg").attr("width",f.fieldWidth).attr("height",d),g=0,h=-20;e.selectAll("g").data(b.resource).enter().append("g").attr("height",f.fieldHeight).attr("width",f.fieldWidth).attr("fill","#cccccc").append("foreignObject").attr("x",g).attr("y",function(){return h+=f.fieldHeight}).attr("height",f.fieldHeight).attr("width",f.fieldWidth).append("xhtml:div").attr("resource-property","").attr("field",function(a,b){return"resource["+b+"]"}).attr("class","text-center field").attr("style","width: 100%")}c.removeAttr("resource-class"),a(c)(b)}}}function d(b){return{restrict:"A",scope:{field:"=",isPk:"="},link:function(c,d){var e=!1;a.isArray(c.field.params)?c.field.params[0]&&c.field.params[0].ref&&(e=!0):a.isObject(c.field.params)&&c.field.params.ref&&(e=!0);var g={width:10,height:f.fieldHeight};if(e){var h=d3.select(d[0]).append("svg").attr("width",f.fieldWidth).attr("height",g.height);h.append("foreignObject").attr("width",f.fieldWidth).attr("height",f.fieldHeight).append("xhtml:div").attr("class","field ref").text(c.field.name+" [ref]"),h.append("foreignObject").attr("width",1).attr("height",f.fieldHeight).append("xhtml:div").attr("port-x",function(){return h[0][0].offsetLeft}).attr("port-y",function(){return h[0][0].offsetTop}).attr("resource-link","").attr("link-to-many",function(){return a.isArray(c.field.params)}).attr("link-to",function(){return a.isArray(c.field.params)?"field.params[0]":"field.params"})}else if(c.field.pk)d.addClass("pk"),d.text("PK: "+c.field.name);else if(a.isArray(c.field.params))d.text(c.field.name+" [Arr]");else if(a.isObject(c.field.params))d.text(c.field.name+" [Nested]");else try{d.text(c.field.name+" ["+c.field.params.substr(0,3)+"]")}catch(i){console.log("caugth error: ",i)}d.removeAttr("resource-property"),b(d)(c)}}}function e(b){return{restrict:"A",scope:{linkToMany:"=",linkTo:"=",portX:"@",portY:"@"},link:function(c,d){function e(){var a=["#FF0020","#FF00CC","#0000FF","#00F9FF","#00FF20","#FFE000"],b=Math.floor(6*Math.random());return a[b]}var g=b.find("resources",c.linkTo.ref);if(g){var h=b.getBaseOffset(),i=parseInt(c.portX),j=parseInt(c.portY)+10,k=!1,l=i-g.right<100;i<=g.left&&(k=!0);var m=[];k?(m.push({x:i+f.fieldWidth,y:j-h}),m.push({x:i+f.fieldWidth+50,y:j-h})):l?(m.push({x:i+f.fieldWidth,y:j-h}),m.push({x:i+f.fieldWidth+50,y:j-h})):(m.push({x:i,y:j-h}),m.push({x:i-50,y:j-h}));var n=Math.floor((g.right-i)/f.columnWidth),o=Math.abs(n);if(o>1)for(var p=Math.floor(i/f.columnWidth),q=p+n,r=k?p+1:p-1;r!==q;){var s=[];a.forEach(b.positions,function(b){a.forEach(b,function(a){a.column==r&&s.push(a)})});var t=s[0],u=Math.abs(j-t.y);a.forEach(s,function(a){var b=Math.abs(j-a.y);u>b&&(t=a,u=j-a.y)});var v=t.y+t.height+50*Math.random(),w=t.x,x=50;k?(m.push({x:w-x,y:v}),m.push({x:w+f.columnWidth-x,y:v})):(m.push({x:w+f.columnWidth+x,y:v}),m.push({x:w-x,y:v})),k?r++:r--}k?(m.push({x:g.left-50,y:g.top+10}),m.push({x:g.left,y:g.top+10})):(m.push({x:g.right+50,y:g.top+10}),m.push({x:g.right,y:g.top+10}));var y=d3.svg.line().x(function(a){return a.x}).y(function(a){return a.y}).tension(.95).interpolate("basis"),z=e(),A=d3.select("#mainCanvas").append("path").attr("d",y(m)).attr("stroke",z).attr("stroke-width",2).attr("fill","none").on("mouseover",function(){d3.select(this).attr("stroke","#F00").attr("stroke-width",10)}).on("mouseleave",function(){d3.select(this).attr("stroke",z).attr("stroke-width",2)}),B=d.parent().parent().parent();B.bind("mouseover",function(){A.attr("stroke","#F00").attr("stroke-width",10)}),B.bind("mouseleave",function(){A.attr("stroke",z).attr("stroke-width",2)})}}}}var f={headerHeight:50,fieldHeight:20,fieldWidth:200,columnWidth:300,vgap:50};a.module("fortuneAdmin.Uml.Directives",["fortuneAdmin.Uml.D3","fortuneAdmin.Uml.Services"]).directive("resourcesCanvas",["$compile","UmlElementsRegistry",b]).directive("resourceClass",["$compile","UmlElementsRegistry",c]).directive("resourceProperty",["$compile","UmlElementsRegistry",d]).directive("resourceLink",["UmlElementsRegistry",e])}(angular),function(a){a.module("fortuneAdmin.Uml",["fortuneAdmin.Uml.Controllers","fortuneAdmin.Uml.Services","fortuneAdmin.Uml.D3","fortuneAdmin.Uml.Directives"])}(angular),function(a){function b(){var b={resources:[],fields:[]},c=0;this.positions={},this.bottomLine=[],this.setBase=function(a){c=a},this.getBaseOffset=function(){return c},this.add=function(a,d,e){e=e.replace(/\n/gi,""),b[a].push({id:e,top:d.offsetTop-c,left:d.offsetLeft,right:d.offsetLeft+d.clientWidth})},this.find=function(c,d){var e=null;return a.forEach(b[c],function(a){a.id===d&&(e=a)}),e},this.remove=function(){},this.clear=function(){b={resources:[],fields:[]},this.positions={},this.bottomLine=[]}}a.module("fortuneAdmin.Uml.Services",[]).service("UmlElementsRegistry",[b])}(angular),angular.module("fortuneAdmin.Services.inflectPort",[]).service("Inflect",[function(){var a,b={},c=a={array:{del:function(a,b){var c=a.indexOf(b);return-1!=c?0==c?a.slice(1):a.slice(0,c).concat(a.slice(c+1)):a},first:function(a){return a[0]},last:function(a){return a[a.length-1]}},string:{gsub:function(b,c,d){var e,f,g,h,i,j,k;if(null==c||null==d)return a.string.value(b);for(j="",k=b;k.length>0;)if(f=k.match(c)){if(j+=k.slice(0,f.index),"function"==typeof d)f[1]=f[1]||f[0],j+=d(f);else if(d.match(/\$[1-9]/)){for(h=f,g=a.array.del(f,void 0);g!==h;)h=g,g=a.array.del(g,void 0);for(f[1]=f[1]||f[0],i=d,e=1;9>=e;e++)g[e]&&(i=a.string.gsub(i,new RegExp("\\$"+e),g[e]));j+=i}else j+=d;k=k.slice(f.index+f[0].length)}else j+=k,k="";return j},upcase:function(b){var c=a.string.gsub(b,/_([a-z])/,function(a){return"_"+a[1].toUpperCase()});return c=a.string.gsub(c,/\/([a-z])/,function(a){return"/"+a[1].toUpperCase()}),c[0].toUpperCase()+c.substr(1)},capitalize:function(b,c){var d=b.toLowerCase();return c||(d=a.string.gsub(d,/\s([a-z])/,function(a){return" "+a[1].toUpperCase()})),d[0].toUpperCase()+d.substr(1)},downcase:function(b){var c=a.string.gsub(b,/_([A-Z])/,function(a){return"_"+a[1].toLowerCase()});return c=a.string.gsub(c,/\/([A-Z])/,function(a){return"/"+a[1].toLowerCase()}),c[0].toLowerCase()+c.substr(1)},value:function(a){return a.substr(0)}}},d=function(a){a.plural(/$/,"s"),a.plural(/s$/i,"s"),a.plural(/(ax|test)is$/i,"$1es"),a.plural(/(octop|vir)us$/i,"$1i"),a.plural(/(octop|vir)i$/i,"$1i"),a.plural(/(alias|status)$/i,"$1es"),a.plural(/(bu)s$/i,"$1ses"),a.plural(/(buffal|tomat)o$/i,"$1oes"),a.plural(/([ti])um$/i,"$1a"),a.plural(/([ti])a$/i,"$1a"),a.plural(/sis$/i,"ses"),a.plural(/(?:([^f])fe|([lr])f)$/i,"$1ves"),a.plural(/(hive)$/i,"$1s"),a.plural(/([^aeiouy]|qu)y$/i,"$1ies"),a.plural(/(x|ch|ss|sh)$/i,"$1es"),a.plural(/(matr|vert|ind)(?:ix|ex)$/i,"$1ices"),a.plural(/([m|l])ouse$/i,"$1ice"),a.plural(/([m|l])ice$/i,"$1ice"),a.plural(/^(ox)$/i,"$1en"),a.plural(/^(oxen)$/i,"$1"),a.plural(/(quiz)$/i,"$1zes"),a.singular(/s$/i,""),a.singular(/(n)ews$/i,"$1ews"),a.singular(/([ti])a$/i,"$1um"),a.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i,"$1sis"),a.singular(/(^analy)ses$/i,"$1sis"),a.singular(/([^f])ves$/i,"$1fe"),a.singular(/(hive)s$/i,"$1"),a.singular(/(tive)s$/i,"$1"),a.singular(/([lr])ves$/i,"$1f"),a.singular(/([^aeiouy]|qu)ies$/i,"$1y"),a.singular(/(s)eries$/i,"$1eries"),a.singular(/(m)ovies$/i,"$1ovie"),a.singular(/(x|ch|ss|sh)es$/i,"$1"),a.singular(/([m|l])ice$/i,"$1ouse"),a.singular(/(bus)es$/i,"$1"),a.singular(/(o)es$/i,"$1"),a.singular(/(shoe)s$/i,"$1"),a.singular(/(cris|ax|test)es$/i,"$1is"),a.singular(/(octop|vir)i$/i,"$1us"),a.singular(/(alias|status)es$/i,"$1"),a.singular(/^(ox)en/i,"$1"),a.singular(/(vert|ind)ices$/i,"$1ex"),a.singular(/(matr)ices$/i,"$1ix"),a.singular(/(quiz)zes$/i,"$1"),a.singular(/(database)s$/i,"$1"),a.irregular("child","children"),a.irregular("person","people"),a.irregular("man","men"),a.irregular("child","children"),a.irregular("sex","sexes"),a.irregular("move","moves"),a.irregular("cow","kine"),a.irregular("zombie","zombies"),a.uncountable(["equipment","information","rice","money","species","series","fish","sheep","jeans"])},e=function(){return this.plurals=[],this.singulars=[],this.uncountables=[],this.humans=[],d(this),this};return e.prototype.plural=function(a,b){"string"==typeof a&&(this.uncountables=c.array.del(this.uncountables,a)),this.uncountables=c.array.del(this.uncountables,b),this.plurals.unshift([a,b])},e.prototype.singular=function(a,b){"string"==typeof a&&(this.uncountables=c.array.del(this.uncountables,a)),this.uncountables=c.array.del(this.uncountables,b),this.singulars.unshift([a,b])},e.prototype.irregular=function(a,b){this.uncountables=c.array.del(this.uncountables,a),this.uncountables=c.array.del(this.uncountables,b),a[0].toUpperCase()==b[0].toUpperCase()?(this.plural(new RegExp("("+a[0]+")"+a.slice(1)+"$","i"),"$1"+b.slice(1)),this.plural(new RegExp("("+b[0]+")"+b.slice(1)+"$","i"),"$1"+b.slice(1)),this.singular(new RegExp("("+b[0]+")"+b.slice(1)+"$","i"),"$1"+a.slice(1))):(this.plural(new RegExp(""+a[0].toUpperCase()+a.slice(1)+"$"),b[0].toUpperCase()+b.slice(1)),this.plural(new RegExp(""+a[0].toLowerCase()+a.slice(1)+"$"),b[0].toLowerCase()+b.slice(1)),this.plural(new RegExp(""+b[0].toUpperCase()+b.slice(1)+"$"),b[0].toUpperCase()+b.slice(1)),this.plural(new RegExp(""+b[0].toLowerCase()+b.slice(1)+"$"),b[0].toLowerCase()+b.slice(1)),this.singular(new RegExp(""+b[0].toUpperCase()+b.slice(1)+"$"),a[0].toUpperCase()+a.slice(1)),this.singular(new RegExp(""+b[0].toLowerCase()+b.slice(1)+"$"),a[0].toLowerCase()+a.slice(1)))},e.prototype.human=function(a,b){this.humans.unshift([a,b])},e.prototype.uncountable=function(a){this.uncountables=this.uncountables.concat(a)},e.prototype.clear=function(a){switch(null==a&&(a="all"),a){case"all":this.plurals=[],this.singulars=[],this.uncountables=[],this.humans=[];default:this[a]=[]}},e.prototype.default=function(){return this.plurals=[],this.singulars=[],this.uncountables=[],this.humans=[],d(this),this},b.inflections=new e,b.inflect=function(a){a(b.inflections)},b.camelize=function(a,b){var d;return null==b&&(b=!0),d=c.string.gsub(a,/\/(.?)/,function(a){return"."+c.string.upcase(a[1])}),d=c.string.gsub(d,/(?:_)(.)/,function(a){return c.string.upcase(a[1])}),b?c.string.upcase(d):c.string.downcase(d)},b.underscore=function(a){var b;return b=c.string.gsub(a,/\./,"/"),b=c.string.gsub(b,/([A-Z]+)([A-Z][a-z])/,"$1_$2"),b=c.string.gsub(b,/([a-z\d])([A-Z])/,"$1_$2"),b=c.string.gsub(b,/-/,"_"),b.toLowerCase()},b.dasherize=function(a){return c.string.gsub(a,/_/,"-")},b.demodulize=function(a){return c.string.gsub(a,/^.*\./,"")},b.foreign_key=function(a,c){return null==c&&(c=!0),b.underscore(b.demodulize(a))+(c?"_id":"id")},b.ordinalize=function(a){var b;if(a=parseInt(a),11===(b=Math.abs(a)%100)||12===b||13===b)return""+a+"th";switch(Math.abs(a)%10){case 1:return""+a+"st";case 2:return""+a+"nd";case 3:return""+a+"rd";default:return""+a+"th"}},b.uncountability=function(a){return b.inflections.uncountables.some(function(b){return null!=a.match(new RegExp("(\\b|_)"+b+"$","i"))})},b.pluralize=function(a){var d,e;if(e=a,""===a||b.uncountability(a))return e;for(var f=0;f<b.inflections.plurals.length&&(d=b.inflections.plurals[f],e=c.string.gsub(e,d[0],d[1]),null==a.match(d[0]));f++);return e},b.singularize=function(a){var d,e;if(d=a,""===a||b.uncountability(a))return d;for(var f=0;f<b.inflections.singulars.length&&(e=b.inflections.singulars[f],d=c.string.gsub(d,e[0],e[1]),!a.match(e[0]));f++);return d},b.humanize=function(a){var d,e;e=a;for(var f=0;f<b.inflections.humans.length;f++)d=b.inflections.humans[f],e=c.string.gsub(e,d[0],d[1]);return e=c.string.gsub(e,/_id$/,""),e=c.string.gsub(e,/_/," "),c.string.capitalize(e,!0)},b.titleize=function(a){var d;return d=b.humanize(b.underscore(a)),d=c.string.gsub(d,/[^a-zA-Z:']/," "),c.string.capitalize(d)},b.tableize=function(a){return b.pluralize(b.underscore(a))},b.classify=function(a){return b.camelize(b.singularize(c.string.gsub(a,/.*\./,"")))},b}]),angular.module("fortuneAdmin.Services",["fortuneAdmin.Services.inflectPort"]),function(a){a.module("fortuneAdmin.Standalone",["ngRoute","fortuneAdmin"]).config(["$routeProvider","$locationProvider","$httpProvider","fortuneAdminProvider",function(a,b,c,d){d.enableNavbar(),d.mountTo(a,""),a.when("/",{templateUrl:"init.html",controller:"initCtrl"}),a.otherwise({redirectTo:"/uml"}),b.html5Mode(!0)
}]).controller("initCtrl",["$scope","$location","fortuneAdmin",function(a,b,c){a.params={host:"http://localhost:1337",namespace:"/api/v1"},a.start=function(){c.setApiHost(a.params.host),c.setApiNamespace(a.params.namespace),b.url("/uml")}}])}(angular);