adding angular-permission
This commit is contained in:
parent
c0ab6df74d
commit
e185f59bb1
|
@ -23,11 +23,6 @@ var FormSchema = new Schema({
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now
|
default: Date.now
|
||||||
},
|
},
|
||||||
// type: {
|
|
||||||
// type: String,
|
|
||||||
// default: 'template',
|
|
||||||
// enum: ['submission', 'template']
|
|
||||||
// },
|
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -39,7 +34,7 @@ var FormSchema = new Schema({
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
form_fields: [Schema.Types.Mixed],
|
form_fields: [FieldSchema],
|
||||||
|
|
||||||
submissions: [{
|
submissions: [{
|
||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
|
@ -57,6 +52,10 @@ var FormSchema = new Schema({
|
||||||
pdfFieldMap: {
|
pdfFieldMap: {
|
||||||
type: Schema.Types.Mixed
|
type: Schema.Types.Mixed
|
||||||
},
|
},
|
||||||
|
hideFooter: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
isGenerated: {
|
isGenerated: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -113,7 +112,7 @@ FormSchema.pre('save', function (next) {
|
||||||
|
|
||||||
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
|
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
|
||||||
FormSchema.pre('save', function (next) {
|
FormSchema.pre('save', function (next) {
|
||||||
var field;
|
var field, _form_fields;
|
||||||
|
|
||||||
if(this.isGenerated && this.pdf){
|
if(this.isGenerated && this.pdf){
|
||||||
|
|
||||||
|
@ -137,13 +136,22 @@ FormSchema.pre('save', function (next) {
|
||||||
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
||||||
}
|
}
|
||||||
|
|
||||||
field.created = Date.now();
|
// field.created = Date.now();
|
||||||
field.fieldValue = '';
|
field.fieldValue = '';
|
||||||
field.required = true;
|
// field.required = true;
|
||||||
field.disabled = false;
|
//field.disabled = false;
|
||||||
|
|
||||||
// field = new Field(field);
|
// field = new Field(field);
|
||||||
// field.save()
|
// field.save(function(err) {
|
||||||
|
// if (err) {
|
||||||
|
// console.error(err.message);
|
||||||
|
// throw new Error(err.message);
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// _form_fields[i] = this;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
_form_fields[i] = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('NEW FORM_FIELDS: ');
|
console.log('NEW FORM_FIELDS: ');
|
||||||
|
|
|
@ -49,7 +49,7 @@ var FormFieldSchema = new Schema({
|
||||||
},
|
},
|
||||||
required: {
|
required: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: true,
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
"angular-bootstrap": "~0.12.0",
|
"angular-bootstrap": "~0.12.0",
|
||||||
"angular-ui-utils": "~0.1.1",
|
"angular-ui-utils": "~0.1.1",
|
||||||
"angular-ui-router": "~0.2.11",
|
"angular-ui-router": "~0.2.11",
|
||||||
"angular-strap": "~2.2.1"
|
"angular-strap": "~2.2.1",
|
||||||
|
"angular-permission": "~0.3.0"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"angular": "^1.2.21",
|
"angular": "^1.2.21",
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
var ApplicationConfiguration = (function() {
|
var ApplicationConfiguration = (function() {
|
||||||
// Init module configuration options
|
// Init module configuration options
|
||||||
var applicationModuleName = 'medform';
|
var applicationModuleName = 'medform';
|
||||||
var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils'];
|
var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils', 'permission'];
|
||||||
|
|
||||||
// Add a new vertical module
|
// Add a new vertical module
|
||||||
var registerModule = function(moduleName, dependencies) {
|
var registerModule = function(moduleName, dependencies) {
|
||||||
|
|
|
@ -11,16 +11,12 @@ angular.module('core').config(['$stateProvider', '$urlRouterProvider',
|
||||||
state('home', {
|
state('home', {
|
||||||
url: '/',
|
url: '/',
|
||||||
templateUrl: 'modules/core/views/home.client.view.html'
|
templateUrl: 'modules/core/views/home.client.view.html'
|
||||||
}).
|
|
||||||
state('restricted', {
|
|
||||||
'abstract': true,
|
|
||||||
resolve: {
|
|
||||||
authorize: ['Authorization',
|
|
||||||
function(Authorization) {
|
|
||||||
return Authorization.authorize();
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$urlRouterProvider.otherwise( function($injector) {
|
||||||
|
var $state = $injector.get("$state");
|
||||||
|
$state.go('home');
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
|
@ -190,12 +190,14 @@
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-offset-4 col-sm-2">
|
<div class="col-sm-offset-3 col-sm-2">
|
||||||
<button class="btn btn-primary btn-large" type="button" ng-click="createOrUpdate()"><i class="icon-arrow-left icon-white"></i> Save Changes</button>
|
<button class="btn btn-primary btn-large" type="button" ng-click="createOrUpdate()"><i class="icon-arrow-left icon-white"></i> Save Changes</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-1">
|
||||||
<button class="btn btn-primary" type="button" ng-click="previewOn()"><i class="icon-eye-open icon-white"></i> Preview Form</button>
|
<button class="btn btn-primary" type="button" ng-data-href="#!/forms/{{form._id}}/admin"><i class="icon-eye-open icon-white"></i> Cancel</button>
|
||||||
<!-- <button class="btn btn-danger right" type="button" ng-click="reset()"><i class="icon-refresh icon-white"></i> Reset</button> -->
|
</div>
|
||||||
|
<div class="col-sm-1 col-sm-offset-1">
|
||||||
|
<button class="btn btn-secondary" type="button" ng-click="previewOn()"><i class="icon-eye-open icon-white"></i> Preview Form</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
<section data-ng-controller="ViewFormController" data-ng-init="findAll()">
|
<section data-ng-controller="ViewFormController" data-ng-init="findAll()" class="container">
|
||||||
<div class="page-header">
|
<div class="row">
|
||||||
<h1>Forms</h1>
|
<div class="page-header col-xs-10 col-xs-offset-1">
|
||||||
|
<h1>My MedForms</h1>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class=" container">
|
<div class="row container">
|
||||||
<a data-ng-href="#!/forms/create" class="col-md-2 col-md-offset-1 form-item row create-new">
|
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row container create-new">
|
||||||
<div class="title-row col-md-12">
|
<div class="title-row col-xs-12">
|
||||||
<h4 class=" fa fa-plus fa-6"></h4>
|
<h4 class=" fa fa-plus fa-6"></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12 details-row">
|
<div class="col-xs-12 details-row">
|
||||||
|
|
||||||
<small class="list-group-item-text">
|
<small class="list-group-item-text">
|
||||||
Create a new form
|
Create a new form
|
||||||
|
@ -16,11 +18,11 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-md-2 col-md-offset-1 form-item row">
|
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-xs-2 col-xs-offset-1 form-item row">
|
||||||
<div class="title-row col-md-12">
|
<div class="title-row col-xs-12">
|
||||||
<h4 class="list-group-item-heading" data-ng-bind="form.title"></h4>
|
<h4 class="list-group-item-heading" data-ng-bind="form.title"></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12 details-row">
|
<div class="col-xs-12 details-row">
|
||||||
|
|
||||||
<small class="list-group-item-text">
|
<small class="list-group-item-text">
|
||||||
Created on
|
Created on
|
||||||
|
@ -33,7 +35,7 @@
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-warning text-center" data-ng-if="forms.$resolved && !forms.length">
|
<!-- <div class="alert alert-warning text-center" data-ng-if="forms.$resolved && !forms.length">
|
||||||
No forms yet, why don't you <a href="/#!/forms/create">create one</a>?
|
No forms yet, why don't you <a href="/#!/forms/create">create one</a>?
|
||||||
</div>
|
</div> -->
|
||||||
</section>
|
</section>
|
|
@ -4,30 +4,30 @@
|
||||||
<form-directive form="form"></form-directive><hr>
|
<form-directive form="form"></form-directive><hr>
|
||||||
|
|
||||||
|
|
||||||
<section class="navbar navbar-fixed-bottom" style="background-color:rgba(242,242,242,0.5); padding-top:15px;">
|
<section ng-if="!form.hideFooter" class="navbar navbar-fixed-bottom" style="background-color:rgba(242,242,242,0.5); padding-top:15px;">
|
||||||
<div class="container" >
|
<div class="container" >
|
||||||
<nav role="navigation">
|
<nav role="navigation">
|
||||||
<ul class="nav navbar-nav navbar-left" >
|
<ul class="nav navbar-nav navbar-left" >
|
||||||
<li class="">
|
<li class="">
|
||||||
<!-- <p class="lead">{{form | formValidity}} out of {{form.form_fields.length}} answered</p> -->
|
<!-- <p class="lead">{{form | formValidity}} out of {{form.form_fields.length}} answered</p> -->
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li style="padding-right:20px" >
|
<li style="padding-right:20px" >
|
||||||
<a href="/forms/create" class="btn btn-default" ng-hide="authentication.user">create a Medform</a>
|
<a href="/forms/create" class="btn btn-default" ng-hide="authentication.user">create a Medform</a>
|
||||||
</li>
|
</li>
|
||||||
<li style="padding-right:20px" ng-show="authentication.user">
|
<li style="padding-right:20px" ng-show="authentication.user">
|
||||||
<a href="/forms/{{form._id}}/edit" class="btn btn-default">edit this Medform</a>
|
<a href="/forms/{{form._id}}/edit" class="btn btn-default">edit this Medform</a>
|
||||||
</li>
|
</li>
|
||||||
<li style="padding-left:5px">
|
<li style="padding-left:5px">
|
||||||
<div class="btn btn-info" id="focusDownButton">\/</div>
|
<div class="btn btn-info" id="focusDownButton">\/</div>
|
||||||
</li>
|
</li>
|
||||||
<li style="padding-left:5px">
|
<li style="padding-left:5px">
|
||||||
<div class="btn btn-info" id="focusUpButton">/\</div>
|
<div class="btn btn-info" id="focusUpButton">/\</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,53 @@
|
||||||
// 'use strict';
|
// 'use strict';
|
||||||
|
|
||||||
// // Config HTTP Error Handling
|
// Config HTTP Error Handling
|
||||||
// angular.module('users').config(['$httpProvider',
|
angular.module('users').config(['$httpProvider','$q', '$location', 'Principal',
|
||||||
// function($httpProvider) {
|
function($httpProvider, $q, $location, Principal) {
|
||||||
// // Set the httpProvider "not authorized" interceptor
|
// Set the httpProvider "not authorized" interceptor
|
||||||
// $httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
$httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
||||||
// function($q, $location, Principal) {
|
function($q, $location, Principal) {
|
||||||
// return {
|
return {
|
||||||
// responseError: function(rejection) {
|
responseError: function(rejection) {
|
||||||
// switch (rejection.status) {
|
switch (rejection.status) {
|
||||||
// case 401:
|
case 401:
|
||||||
// // Deauthenticate the global user
|
// Deauthenticate the global user
|
||||||
// Principal.authenticate(null);
|
|
||||||
|
|
||||||
// // Redirect to signin page
|
// Redirect to signin page
|
||||||
// $location.path('signin');
|
$location.path('signin');
|
||||||
// break;
|
break;
|
||||||
// case 403:
|
case 403:
|
||||||
// // Add unauthorized behaviour
|
// Add unauthorized behaviour
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return $q.reject(rejection);
|
return $q.reject(rejection);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
// ]);
|
]);
|
||||||
// }
|
}
|
||||||
// ]);
|
]).config(['Permission', 'Principal',
|
||||||
|
function($Permission, Principal) {
|
||||||
|
var User = Principal.identity();
|
||||||
|
Permission.defineRole('anonymous', function (stateParams) {
|
||||||
|
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||||
|
if ( !User || !Principal.isInAnyRole() ) {
|
||||||
|
return true; // Is anonymous
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).defineRole('admin', function (stateParams) {
|
||||||
|
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||||
|
if (Principal.isInRole('admin')) {
|
||||||
|
return true; // Is anonymous
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).defineRole('admin', function (stateParams) {
|
||||||
|
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||||
|
if (Principal.isInRole('user') && !Principal.isInRole('admin') ) {
|
||||||
|
return true; // Is anonymous
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Reference in a new issue