Commit 9b3991ac authored by Evren Kutar's avatar Evren Kutar

dynamic dispatch with function dispatchClientCmd

routes identical with client_cmd
parent 06f9ed64
...@@ -22,42 +22,42 @@ app.config(['$routeProvider', function ($routeProvider, $route) { ...@@ -22,42 +22,42 @@ app.config(['$routeProvider', function ($routeProvider, $route) {
// use crud without selected user // use crud without selected user
// important: regex urls must be defined later than static ones // important: regex urls must be defined later than static ones
.when('/:wf/', { .when('/:wf/', {
templateUrl: 'components/wf/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDCtrl' controller: 'CRUDCtrl'
}) })
.when('/:wf/list', { .when('/:wf/list', {
templateUrl: 'components/crud/templates/list.html', templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl' controller: 'CRUDListCtrl'
}) })
.when('/:wf/add', { .when('/:wf/form', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDFormCtrl'
}) })
.when('/:wf/edit/:key', { .when('/:wf/form/:key', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDFormCtrl'
}) })
.when('/:wf/detail/:key', { .when('/:wf/show/:key', {
templateUrl: 'components/crud/templates/show.html', templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl' controller: 'CRUDShowCtrl'
}) })
.when('/:wf/:model', { .when('/:wf/:model', {
templateUrl: 'components/wf/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDCtrl' controller: 'CRUDCtrl'
}) })
.when('/:wf/:model/list', { .when('/:wf/:model/list', {
templateUrl: 'components/crud/templates/list.html', templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl' controller: 'CRUDListCtrl'
}) })
.when('/:wf/:model/add', { .when('/:wf/:model/form', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDFormCtrl'
}) })
.when('/:wf/:model/edit/:key', { .when('/:wf/:model/form/:key', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/form.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDFormCtrl'
}) })
.when('/:wf/:model/detail/:key', { .when('/:wf/:model/show/:key', {
templateUrl: 'components/crud/templates/show.html', templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl' controller: 'CRUDShowCtrl'
}) })
......
...@@ -55,7 +55,7 @@ crud.controller('CRUDCtrl', function ($scope, $routeParams, Generator, CrudUtili ...@@ -55,7 +55,7 @@ crud.controller('CRUDCtrl', function ($scope, $routeParams, Generator, CrudUtili
* which provide a form with form generator. * which provide a form with form generator.
*/ */
crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $http, $log, $modal, $timeout, Generator, $routeParams, CrudUtility) { crud.controller('CRUDFormCtrl', function ($scope, $rootScope, $location, $http, $log, $modal, $timeout, Generator, $routeParams, CrudUtility) {
// get form with generator // get form with generator
if ($routeParams.pageData) { if ($routeParams.pageData) {
CrudUtility.generateParam($scope, Generator.getPageData(), 'form'); CrudUtility.generateParam($scope, Generator.getPageData(), 'form');
......
<div class="container" ng-app="ulakbus.crud">
<div class="col-md-6">
<h1>{{ schema.title }}</h1>
<form name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(formgenerated)"></form>
</div>
</div>
\ No newline at end of file
...@@ -206,12 +206,6 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c ...@@ -206,12 +206,6 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
// get model objects from db and add to select list // get model objects from db and add to select list
scope.form[scope.form.indexOf(k)] = formitem; scope.form[scope.form.indexOf(k)] = formitem;
//scope.$broadcast('schemaFormRedraw');
// todo: make lines below work properly
//if (scope.model[v].indexOf("TMP_") > -1) {
// scope.model[v] = null;
//}
} }
if (v.type === 'ListNode' || v.type === 'Node') { if (v.type === 'ListNode' || v.type === 'Node') {
...@@ -307,7 +301,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c ...@@ -307,7 +301,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
link += "/" + page; link += "/" + page;
if (page === 'edit/' || page === 'detail/') { if (value.key) {
link += value.key; link += value.key;
} }
...@@ -321,12 +315,12 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c ...@@ -321,12 +315,12 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
// call add link once // call add link once
if (!itemlist.addLink) { if (!itemlist.addLink) {
itemlist.addLink = makelink("add/"); itemlist.addLink = makelink("form/");
} }
if (value !== '-1') { if (value !== '-1') {
value.detailLink = makelink("detail/"); value.detailLink = makelink("show/");
value.editLink = makelink("edit/"); value.editLink = makelink("form/");
} }
}); });
}; };
...@@ -453,41 +447,31 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c ...@@ -453,41 +447,31 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
} }
$location.path(pathUrl).search(angular.fromJson({pageData: true})); $location.path(pathUrl).search(angular.fromJson({pageData: true}));
} }
if (client_cmd.indexOf('form') > -1 && client_cmd.indexOf('list') < 0) {
data[$scope.form_params.param] = $scope.form_params.id;
data['model'] = $scope.form_params.model;
data['wf'] = $scope.form_params.wf;
data['param'] = $scope.form_params.param;
data['param_id'] = $scope.form_params.id;
generator.setPageData(data);
redirectTo($scope, 'add');
}
if (client_cmd.indexOf('list') > -1 && client_cmd.indexOf('form') < 0) { // client_cmd can be in ['list', 'form', 'show', 'reload', 'reset']
function dispatchClientCmd() {
data[$scope.form_params.param] = $scope.form_params.id; data[$scope.form_params.param] = $scope.form_params.id;
data['model'] = $scope.form_params.model; data['model'] = $scope.form_params.model;
data['wf'] = $scope.form_params.wf; data['wf'] = $scope.form_params.wf;
data['param'] = $scope.form_params.param; data['param'] = $scope.form_params.param;
data['param_id'] = $scope.form_params.id; data['param_id'] = $scope.form_params.id;
generator.setPageData(data); generator.setPageData(data);
generator.itemLinksGenerator($scope, data); if (client_cmd[0] === 'list') {
generator.itemLinksGenerator($scope, data);
redirectTo($scope, 'list'); }
}
if (client_cmd.indexOf('form') > -1 && client_cmd.indexOf('list') > -1) {
// todo: will be tested
generator.generate($scope, data);
generator.itemLinksGenerator($scope, data);
data[$scope.form_params.param] = $scope.form_params.id;
redirectTo($scope, 'formwithlist');
}
if (client_cmd.indexOf('show') > -1) { redirectTo($scope, client_cmd[0]);
generator.setPageData(data);
redirectTo($scope, 'detail');
} }
dispatchClientCmd();
//if (client_cmd.indexOf('form') > -1 && client_cmd.indexOf('list') > -1) {
// // todo: controller will be created and tested
// generator.generate($scope, data);
// generator.itemLinksGenerator($scope, data);
// data[$scope.form_params.param] = $scope.form_params.id;
// redirectTo($scope, 'formwithlist');
//}
}; };
/** /**
......
...@@ -13,7 +13,6 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -13,7 +13,6 @@ app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(function ($q, $rootScope, $location, $timeout) { $httpProvider.interceptors.push(function ($q, $rootScope, $location, $timeout) {
return { return {
'request': function (config) { 'request': function (config) {
// todo: delete console logs
if (config.method === "POST") { if (config.method === "POST") {
// to prevent OPTIONS preflight request // to prevent OPTIONS preflight request
config.headers["Content-Type"] = "text/plain"; config.headers["Content-Type"] = "text/plain";
...@@ -100,7 +99,6 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -100,7 +99,6 @@ app.config(['$httpProvider', function ($httpProvider) {
} }
} }
if (rejection.status === 403) { if (rejection.status === 403) {
console.log(403);
if (rejection.data.is_login === true) { if (rejection.data.is_login === true) {
$rootScope.loggedInUser = true; $rootScope.loggedInUser = true;
if ($location.path() === "/login") { if ($location.path() === "/login") {
...@@ -112,15 +110,10 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -112,15 +110,10 @@ app.config(['$httpProvider', function ($httpProvider) {
$rootScope.$broadcast('show_notifications', rejection.data); $rootScope.$broadcast('show_notifications', rejection.data);
if (rejection.status === 404) { if (rejection.status === 404) {
console.log(404);
errorModal(); errorModal();
//$location.path("/error/404");
} }
// server 500 error returns with -1 on status.
//if (rejection.status === -1 && rejection.config.data.model) {
if (rejection.status === 500) { if (rejection.status === 500) {
errorModal(); errorModal();
//$location.path("/error/500");
} }
return $q.reject(rejection); return $q.reject(rejection);
} }
......
This diff is collapsed.
angular.module('templates-prod', ['components/auth/login.html', 'components/crud/templates/add.html', 'components/crud/templates/edit.html', 'components/crud/templates/list.html', 'components/crud/templates/show.html', 'components/dashboard/dashboard.html', 'components/debug/debug.html', 'components/devSettings/devSettings.html', 'components/error_pages/404.html', 'components/error_pages/500.html', 'components/uitemplates/404.html', 'components/uitemplates/500.html', 'components/wf/templates/add.html', 'components/wf/templates/edit.html', 'components/wf/templates/list.html', 'components/wf/templates/show.html', 'shared/templates/add.html', 'shared/templates/datefield.html', 'shared/templates/directives/chat.html', 'shared/templates/directives/header-breadcrumb.html', 'shared/templates/directives/header-notification.html', 'shared/templates/directives/header-sub-menu.html', 'shared/templates/directives/menuCollapse.html', 'shared/templates/directives/msgbox.html', 'shared/templates/directives/notifications.html', 'shared/templates/directives/selected-user.html', 'shared/templates/directives/sidebar-notification.html', 'shared/templates/directives/sidebar-search.html', 'shared/templates/directives/sidebar.html', 'shared/templates/directives/stats.html', 'shared/templates/directives/timeline.html', 'shared/templates/fieldset.html', 'shared/templates/foreignKey.html', 'shared/templates/linkedModelModalContent.html', 'shared/templates/listnodeModalContent.html', 'shared/templates/modalContent.html', 'shared/templates/nodeTable.html', 'shared/templates/select.html']); angular.module('templates-prod', ['components/auth/login.html', 'components/crud/templates/form.html', 'components/crud/templates/list.html', 'components/crud/templates/show.html', 'components/dashboard/dashboard.html', 'components/debug/debug.html', 'components/devSettings/devSettings.html', 'components/error_pages/404.html', 'components/error_pages/500.html', 'components/uitemplates/404.html', 'components/uitemplates/500.html', 'components/wf/templates/add.html', 'components/wf/templates/edit.html', 'components/wf/templates/list.html', 'components/wf/templates/show.html', 'shared/templates/add.html', 'shared/templates/datefield.html', 'shared/templates/directives/chat.html', 'shared/templates/directives/header-breadcrumb.html', 'shared/templates/directives/header-notification.html', 'shared/templates/directives/header-sub-menu.html', 'shared/templates/directives/menuCollapse.html', 'shared/templates/directives/msgbox.html', 'shared/templates/directives/notifications.html', 'shared/templates/directives/selected-user.html', 'shared/templates/directives/sidebar-notification.html', 'shared/templates/directives/sidebar-search.html', 'shared/templates/directives/sidebar.html', 'shared/templates/directives/stats.html', 'shared/templates/directives/timeline.html', 'shared/templates/fieldset.html', 'shared/templates/foreignKey.html', 'shared/templates/linkedModelModalContent.html', 'shared/templates/listnodeModalContent.html', 'shared/templates/modalContent.html', 'shared/templates/nodeTable.html', 'shared/templates/select.html']);
angular.module("components/auth/login.html", []).run(["$templateCache", function($templateCache) { angular.module("components/auth/login.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/auth/login.html", $templateCache.put("components/auth/login.html",
...@@ -20,8 +20,8 @@ angular.module("components/auth/login.html", []).run(["$templateCache", function ...@@ -20,8 +20,8 @@ angular.module("components/auth/login.html", []).run(["$templateCache", function
"</div>"); "</div>");
}]); }]);
angular.module("components/crud/templates/add.html", []).run(["$templateCache", function($templateCache) { angular.module("components/crud/templates/form.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/crud/templates/add.html", $templateCache.put("components/crud/templates/form.html",
"<div class=\"container\">\n" + "<div class=\"container\">\n" +
" <h1>{{ schema.title }}</h1>\n" + " <h1>{{ schema.title }}</h1>\n" +
"\n" + "\n" +
...@@ -65,16 +65,6 @@ angular.module("components/crud/templates/add.html", []).run(["$templateCache", ...@@ -65,16 +65,6 @@ angular.module("components/crud/templates/add.html", []).run(["$templateCache",
"</div>"); "</div>");
}]); }]);
angular.module("components/crud/templates/edit.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/crud/templates/edit.html",
"<div class=\"container\" ng-app=\"ulakbus.crud\">\n" +
" <div class=\"col-md-6\">\n" +
" <h1>{{ schema.title }}</h1>\n" +
" <form name=\"formgenerated\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" ng-submit=\"onSubmit(formgenerated)\"></form>\n" +
" </div>\n" +
"</div>");
}]);
angular.module("components/crud/templates/list.html", []).run(["$templateCache", function($templateCache) { angular.module("components/crud/templates/list.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/crud/templates/list.html", $templateCache.put("components/crud/templates/list.html",
"<div class=\"starter-template container\">\n" + "<div class=\"starter-template container\">\n" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment