Commit 50a15184 authored by Evren Kutar's avatar Evren Kutar

header logout add

sidebar dashboard link
crud delete todo
model type object handle with foreignkey template
form service handle model type schema object
parent f6c60438
......@@ -52,14 +52,14 @@ app.config(['$routeProvider', function ($routeProvider) {
$rootScope.loggedInUser ? $rootScope.loggedInUser : false;
$rootScope.$on("$routeChangeStart", function (event, next, current) {
if ($rootScope.loggedInUser == null) {
// no logged user, redirect to /login
if (next.templateUrl === "login/login.html") {
} else {
$location.path("/login");
}
}
//if ($rootScope.loggedInUser == null) {
// // no logged user, redirect to /login
// if (next.templateUrl === "login/login.html") {
//
// } else {
// $location.path("/login");
// }
//}
});
}).config(['$httpProvider', function($httpProvider) {
// to send cookies CORS
......
......@@ -46,9 +46,6 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
};
});
// todo: for single point of failure code a "get item" service and use it to
// retrieve list and single item
/**
* CRUD List Controller
*/
......
......@@ -200,7 +200,7 @@
</li>
<li><a href="http://www.strapui.com/"><i class="fa fa-eye fa-fw"></i> Premium Angular Themes</a></li>
<li class="divider"></li>
<li><a ui-sref="login"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
<li><a ui-sref="login" href="javascript:void(0);" logout><i class="fa fa-sign-out fa-fw"></i> Logout</a>
</li>
</ul>
<!-- /.dropdown-user -->
......
......@@ -3,7 +3,7 @@
<ul class="nav in" id="side-menu">
<sidebar-search></sidebar-search>
<li ui-sref-active="active">
<a ui-sref="dashboard.home"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
<a href="#/dashboard"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
</li>
<!--<li ui-sref-active="active"><a href="#/staffs" translate>Staffs</a></li>-->
<!--<li ui-sref-active="active"><a href="#/staff/add" translate>New Staff</a></li>-->
......
<div class="form-group {{form.htmlClass}} schema-form-select col-md-12"
ng-class="{'has-error': form.disableErrorState !== true && hasError(), 'has-success': form.disableSuccessState !== true && hasSuccess(), 'has-feedback': form.feedback !== false}">
<div class="col-md-8">
<label class="control-label {{form.labelHtmlClass}}" ng-show="showTitle()">
{{form.title}}
</label>
<select ng-model="$$value$$"
ng-model-options="form.ngModelOptions"
ng-disabled="form.readonly"
sf-changed="form"
class="form-control {{form.fieldHtmlClass}}"
schema-validate="form"
ng-options="item.value as item.name group by item.group for item in form.titleMap track by item[form.trackBy]"
name="{{form.key.slice(-1)[0]}}">
</select>
<div class="help-block" sf-message="form.description"></div>
</div>
<div class="col-md-4"><a href="javascript:void(0);" logout><i class="fa fa-plus-circle fa-fw"></i></a></div>
</div>
\ No newline at end of file
......@@ -25,11 +25,46 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
);
// if fieldset in form, make it collapsable with template
scope.listnodeform = {};
angular.forEach(scope.schema.properties, function(k, v){
// check if type date and if type date found change it to string
// check if type is date and if type date found change it to string
// and give it 'format':'date' property
if (k.type == 'date') {k.type='string'; k.format='date'}
// if type is model use foreignKey.html template to show them
// TODO: treat models as foreign keys
if (k.type == 'model') {
var formitem = scope.form[scope.form.indexOf(v)];
formitem = {
"type": "template",
"templateUrl": "shared/templates/foreignKey.html",
"title": k.model_name,
};
k.title = k.model_name;
var modelscope = scope;
modelscope.form_params = {model: k.model_name};
// get model objects from db and add to select list
generator.get_list(modelscope).then(function(res){
formitem.titleMap = [];
angular.forEach(res.data.objects, function(item){
console.log(item);
formitem.titleMap.push({
"value": item.key,
"name": item.data.name ? item.data.name : item.data.username
});
});
});
scope.form[scope.form.indexOf(v)] = formitem;
debugger;
}
});
// catch node and listnode and edit their schema and form props
if ((scope.listnode && scope.listnodes[0]) || (scope.nodes && scope.nodes[0])) {
angular.forEach(scope.form, function (key, val) {
if (typeof key == "object" && key.type == "fieldset") {
......@@ -99,6 +134,14 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
generator.group = function (formObject) {
return formObject;
};
generator.dateformatter = function(formObject){
//angular.forEach(formObject.objects, function(k, v) {
// check if date string and convert to date object
// todo: catch date object and convert
//debugger;
//});
return formObject;
};
generator.get_form = function (scope) {
return $http
.post(generator.makeUrl(scope.url), scope.form_params)
......@@ -111,6 +154,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
return $http
.post(generator.makeUrl(scope.url), scope.form_params)
.then(function (res) {
generator.dateformatter(res);
return res;
// todo: cover all other exceptions (4xx, 5xx)
});
......@@ -119,6 +163,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
return $http
.post(generator.makeUrl(scope.url), scope.form_params)
.then(function (res) {
generator.dateformatter(res);
return res;
// todo: cover all other exceptions (4xx, 5xx)
});
......@@ -141,7 +186,13 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
}
};
generator.submit = function ($scope) {
data = {"form": $scope.model, "cmd": $scope.form_params.cmd, "subcmd": "do_list", "model": $scope.form_params.model};
data = {
"form": $scope.model,
"cmd": $scope.form_params.cmd,
"subcmd": "do_list",
"model": $scope.form_params.model,
"token": $scope.token
};
if ($scope.object_id) {
var get_diff = FormDiff.get_diff($scope.model, $scope.initialModel);
var data = {
......
......@@ -26,7 +26,7 @@ app.config(['$httpProvider', function ($httpProvider) {
//Will only be called for HTTP up to 300
if(response.data.is_login===true){
$rootScope.loggedInUser = response.data.is_login;
$location.replace();
//$location.replace();
if($location.path()==="/login"){
$location.path("/dashboard");
}
......
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