diff --git a/front/core/components/label-value/label-value.js b/front/core/components/label-value/label-value.js
index 87ae5f08e..e641ede13 100644
--- a/front/core/components/label-value/label-value.js
+++ b/front/core/components/label-value/label-value.js
@@ -1,17 +1,17 @@
import ngModule from '../../module';
+import Component from 'core/lib/component';
import './style.scss';
-export default class Controller {
- constructor($element, $translate, $attrs) {
- this.element = $element[0];
- this._ = $translate;
+export default class Controller extends Component {
+ constructor($element, $, $attrs) {
+ super($element, $);
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
}
set label(value) {
let label = this.element.querySelector('vn-label');
- label.textContent = this._.instant(value);
+ label.textContent = this.$t(value);
this._label = value;
}
@@ -55,7 +55,7 @@ export default class Controller {
element.textContent = hasValue ? this.value : '-';
}
}
-Controller.$inject = ['$element', '$translate', '$attrs'];
+Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnLabelValue', {
controller: Controller,
diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js
index 02b92dda6..0709e209e 100644
--- a/front/core/components/watcher/watcher.js
+++ b/front/core/components/watcher/watcher.js
@@ -181,7 +181,7 @@ export default class Watcher extends Component {
* Notifies the user that the data has been saved.
*/
notifySaved() {
- this.vnApp.showSuccess(this._.instant('Data saved!'));
+ this.vnApp.showSuccess(this.$t('Data saved!'));
}
setPristine() {
diff --git a/front/core/components/wday-picker/style.scss b/front/core/components/wday-picker/style.scss
index ba2f3347f..c50b20718 100644
--- a/front/core/components/wday-picker/style.scss
+++ b/front/core/components/wday-picker/style.scss
@@ -3,6 +3,9 @@
vn-wday-picker {
text-align: center;
+ &:focus {
+ outline: solid 1px rgba(0, 0, 0, .1);
+ }
& > span {
@extend %clickable;
border-radius: 50%;
diff --git a/front/core/lib/component.js b/front/core/lib/component.js
index 923657d1a..5288ae873 100644
--- a/front/core/lib/component.js
+++ b/front/core/lib/component.js
@@ -1,3 +1,4 @@
+import ngModule from '../module';
import EventEmitter from './event-emitter';
import {kebabToCamel} from './string';
@@ -44,5 +45,30 @@ export default class Component extends EventEmitter {
get document() {
return this.element.ownerDocument;
}
+
+ /**
+ * Translates an string.
+ *
+ * @param {String} string String to translate
+ * @param {Array} params Translate parameters
+ * @return {String} The translated string
+ */
+ $t(string, params) {
+ return this.$translate.instant(string, params);
+ }
}
Component.$inject = ['$element', '$scope'];
+
+function runFn($translate, $q, $http, vnApp, $state, $stateParams) {
+ Object.assign(Component.prototype, {
+ $translate,
+ $q,
+ $http,
+ vnApp,
+ $state,
+ $params: $stateParams
+ });
+}
+runFn.$inject = ['$translate', '$q', '$http', 'vnApp', '$state', '$stateParams'];
+
+ngModule.run(runFn);
diff --git a/front/core/lib/section.js b/front/core/lib/section.js
deleted file mode 100644
index 7e59bb8b3..000000000
--- a/front/core/lib/section.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import Component from './component';
-
-/**
- * Class with commonly injected services assigned as properties. It also has
- * abbreviations for commonly used methods like tranlation.
- *
- * @property {Object} $translate Angular tranlation service
- * @property {Object} $http Angular HTTP service
- * @property {Object} $state Router state service
- * @property {Object} $stateParams Router state parameters
- */
-export default class Section extends Component {
- constructor($element, $scope, $translate, $http, $state) {
- super($element, $scope);
- Object.assign(this, {
- $translate,
- $http,
- $state,
- $stateParams: $state.params
- });
- }
-
- /**
- * Translates an string.
- *
- * @param {String} string String to translate
- * @param {Array} params Translate parameters
- * @return {String} The translated string
- */
- _(string, params) {
- return this.$translate.instant(string, params, );
- }
-}
-Section.$inject = ['$element', '$scope', '$translate', '$http', '$state'];
diff --git a/front/core/services/acl-service.js b/front/core/services/acl-service.js
index d286ec85f..24de35a57 100644
--- a/front/core/services/acl-service.js
+++ b/front/core/services/acl-service.js
@@ -4,10 +4,12 @@ class AclService {
constructor($http) {
this.$http = $http;
}
+
reset() {
this.user = null;
this.roles = null;
}
+
load() {
return this.$http.get('/api/Accounts/acl').then(res => {
this.user = res.data.user;
@@ -19,6 +21,7 @@ class AclService {
}
});
}
+
hasAny(roles) {
if (this.roles) {
for (let role of roles) {
diff --git a/front/core/services/auth.js b/front/core/services/auth.js
index 44d9f16d9..1bf9a1015 100644
--- a/front/core/services/auth.js
+++ b/front/core/services/auth.js
@@ -20,6 +20,7 @@ export default class Auth {
loggedIn: false
});
}
+
initialize() {
let criteria = {
to: state => state.name != 'login'
@@ -42,6 +43,7 @@ export default class Auth {
return redirectToLogin();
});
}
+
login(user, password, remember) {
if (!user)
return this.$q.reject(new UserError('Please enter your username'));
@@ -54,6 +56,7 @@ export default class Auth {
return this.$http.post('/api/Accounts/login', params).then(
json => this.onLoginOk(json, remember));
}
+
onLoginOk(json, remember) {
this.vnToken.set(json.data.token, remember);
@@ -65,6 +68,7 @@ export default class Auth {
this.$state.go('home');
});
}
+
logout() {
let promise = this.$http.post('/api/Accounts/logout', null, {
headers: {Authorization: this.vnToken.token}
@@ -78,6 +82,7 @@ export default class Auth {
return promise;
}
+
loadAcls() {
return this.aclService.load()
.then(() => {
diff --git a/front/salix/components/home/home.js b/front/salix/components/home/home.js
index 8b71f1f39..367880b31 100644
--- a/front/salix/components/home/home.js
+++ b/front/salix/components/home/home.js
@@ -1,16 +1,17 @@
import ngModule from '../../module';
+import Component from 'core/lib/component';
import './style.scss';
-export default class Controller {
- constructor(vnModules, $state, $translate, $sce) {
+export default class Controller extends Component {
+ constructor($element, $, vnModules, $sce) {
+ super($element, $);
this.modules = vnModules.get();
- this.$state = $state;
- this._ = $translate;
this.$sce = $sce;
}
+
getModuleName(mod) {
let getName = mod => {
- let name = this._.instant(mod.name);
+ let name = this.$t(mod.name);
let upper = name.toUpperCase();
if (!mod.keyBind) return name;
let index = upper.indexOf(mod.keyBind);
@@ -25,8 +26,7 @@ export default class Controller {
return this.$sce.trustAsHtml(getName(mod));
}
}
-
-Controller.$inject = ['vnModules', '$state', '$translate', '$sce'];
+Controller.$inject = ['$element', '$scope', 'vnModules', '$sce'];
ngModule.component('vnHome', {
template: require('./home.html'),
diff --git a/modules/agency/front/calendar/index.js b/modules/agency/front/calendar/index.js
index 00c6a7dff..d4e6fe37c 100644
--- a/modules/agency/front/calendar/index.js
+++ b/modules/agency/front/calendar/index.js
@@ -1,10 +1,10 @@
import ngModule from '../module';
-import Section from 'core/lib/section';
+import Component from 'core/lib/component';
import './style.scss';
-class Controller extends Section {
- constructor($el, $, $t, $http, $state) {
- super($el, $, $t, $http, $state);
+class Controller extends Component {
+ constructor($element, $) {
+ super($element, $);
this.nMonths = 4;
let date = new Date();
diff --git a/modules/agency/front/events/index.js b/modules/agency/front/events/index.js
index 593e617db..656b8b6e0 100644
--- a/modules/agency/front/events/index.js
+++ b/modules/agency/front/events/index.js
@@ -1,15 +1,14 @@
import ngModule from '../module';
-import Section from 'core/lib/section';
+import Component from 'core/lib/component';
-class Controller extends Section {
- constructor($el, $, $t, $http, $state, $q, vnWeekDays) {
- super($el, $, $t, $http, $state);
- this.$q = $q;
+class Controller extends Component {
+ constructor($element, $, vnWeekDays) {
+ super($element, $);
this.vnWeekDays = vnWeekDays;
this.editMode = 'include';
- this.path = `api/Zones/${this.$stateParams.id}/events`;
- this.exclusionsPath = `api/Zones/${this.$stateParams.id}/exclusions`;
+ this.path = `api/Zones/${this.$params.id}/events`;
+ this.exclusionsPath = `api/Zones/${this.$params.id}/exclusions`;
this.refresh();
}
@@ -190,7 +189,7 @@ class Controller extends Section {
.then(() => this.refresh());
}
}
-Controller.$inject = ['$element', '$scope', '$translate', '$http', '$state', '$q', 'vnWeekDays'];
+Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
ngModule.component('vnZoneEvents', {
template: require('./index.html'),
diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html
index 4fcef0192..ca885a6b4 100644
--- a/modules/agency/front/location/index.html
+++ b/modules/agency/front/location/index.html
@@ -1,6 +1,6 @@