vnCompent with most common services as properties
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
parent
4685b4166b
commit
ee196df2ff
|
@ -1,17 +1,17 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller extends Component {
|
||||||
constructor($element, $translate, $attrs) {
|
constructor($element, $, $attrs) {
|
||||||
this.element = $element[0];
|
super($element, $);
|
||||||
this._ = $translate;
|
|
||||||
this.hasInfo = Boolean($attrs.info);
|
this.hasInfo = Boolean($attrs.info);
|
||||||
this.info = $attrs.info || null;
|
this.info = $attrs.info || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
set label(value) {
|
set label(value) {
|
||||||
let label = this.element.querySelector('vn-label');
|
let label = this.element.querySelector('vn-label');
|
||||||
label.textContent = this._.instant(value);
|
label.textContent = this.$t(value);
|
||||||
this._label = value;
|
this._label = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ export default class Controller {
|
||||||
element.textContent = hasValue ? this.value : '-';
|
element.textContent = hasValue ? this.value : '-';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$element', '$translate', '$attrs'];
|
Controller.$inject = ['$element', '$scope', '$attrs'];
|
||||||
|
|
||||||
ngModule.component('vnLabelValue', {
|
ngModule.component('vnLabelValue', {
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
|
|
|
@ -181,7 +181,7 @@ export default class Watcher extends Component {
|
||||||
* Notifies the user that the data has been saved.
|
* Notifies the user that the data has been saved.
|
||||||
*/
|
*/
|
||||||
notifySaved() {
|
notifySaved() {
|
||||||
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
setPristine() {
|
setPristine() {
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
vn-wday-picker {
|
vn-wday-picker {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: solid 1px rgba(0, 0, 0, .1);
|
||||||
|
}
|
||||||
& > span {
|
& > span {
|
||||||
@extend %clickable;
|
@extend %clickable;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ngModule from '../module';
|
||||||
import EventEmitter from './event-emitter';
|
import EventEmitter from './event-emitter';
|
||||||
import {kebabToCamel} from './string';
|
import {kebabToCamel} from './string';
|
||||||
|
|
||||||
|
@ -44,5 +45,30 @@ export default class Component extends EventEmitter {
|
||||||
get document() {
|
get document() {
|
||||||
return this.element.ownerDocument;
|
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'];
|
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);
|
||||||
|
|
|
@ -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'];
|
|
|
@ -4,10 +4,12 @@ class AclService {
|
||||||
constructor($http) {
|
constructor($http) {
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.user = null;
|
this.user = null;
|
||||||
this.roles = null;
|
this.roles = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
return this.$http.get('/api/Accounts/acl').then(res => {
|
return this.$http.get('/api/Accounts/acl').then(res => {
|
||||||
this.user = res.data.user;
|
this.user = res.data.user;
|
||||||
|
@ -19,6 +21,7 @@ class AclService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hasAny(roles) {
|
hasAny(roles) {
|
||||||
if (this.roles) {
|
if (this.roles) {
|
||||||
for (let role of roles) {
|
for (let role of roles) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ export default class Auth {
|
||||||
loggedIn: false
|
loggedIn: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
let criteria = {
|
let criteria = {
|
||||||
to: state => state.name != 'login'
|
to: state => state.name != 'login'
|
||||||
|
@ -42,6 +43,7 @@ export default class Auth {
|
||||||
return redirectToLogin();
|
return redirectToLogin();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
login(user, password, remember) {
|
login(user, password, remember) {
|
||||||
if (!user)
|
if (!user)
|
||||||
return this.$q.reject(new UserError('Please enter your username'));
|
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(
|
return this.$http.post('/api/Accounts/login', params).then(
|
||||||
json => this.onLoginOk(json, remember));
|
json => this.onLoginOk(json, remember));
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoginOk(json, remember) {
|
onLoginOk(json, remember) {
|
||||||
this.vnToken.set(json.data.token, remember);
|
this.vnToken.set(json.data.token, remember);
|
||||||
|
|
||||||
|
@ -65,6 +68,7 @@ export default class Auth {
|
||||||
this.$state.go('home');
|
this.$state.go('home');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
let promise = this.$http.post('/api/Accounts/logout', null, {
|
let promise = this.$http.post('/api/Accounts/logout', null, {
|
||||||
headers: {Authorization: this.vnToken.token}
|
headers: {Authorization: this.vnToken.token}
|
||||||
|
@ -78,6 +82,7 @@ export default class Auth {
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAcls() {
|
loadAcls() {
|
||||||
return this.aclService.load()
|
return this.aclService.load()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller extends Component {
|
||||||
constructor(vnModules, $state, $translate, $sce) {
|
constructor($element, $, vnModules, $sce) {
|
||||||
|
super($element, $);
|
||||||
this.modules = vnModules.get();
|
this.modules = vnModules.get();
|
||||||
this.$state = $state;
|
|
||||||
this._ = $translate;
|
|
||||||
this.$sce = $sce;
|
this.$sce = $sce;
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleName(mod) {
|
getModuleName(mod) {
|
||||||
let getName = mod => {
|
let getName = mod => {
|
||||||
let name = this._.instant(mod.name);
|
let name = this.$t(mod.name);
|
||||||
let upper = name.toUpperCase();
|
let upper = name.toUpperCase();
|
||||||
if (!mod.keyBind) return name;
|
if (!mod.keyBind) return name;
|
||||||
let index = upper.indexOf(mod.keyBind);
|
let index = upper.indexOf(mod.keyBind);
|
||||||
|
@ -25,8 +26,7 @@ export default class Controller {
|
||||||
return this.$sce.trustAsHtml(getName(mod));
|
return this.$sce.trustAsHtml(getName(mod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Controller.$inject = ['$element', '$scope', 'vnModules', '$sce'];
|
||||||
Controller.$inject = ['vnModules', '$state', '$translate', '$sce'];
|
|
||||||
|
|
||||||
ngModule.component('vnHome', {
|
ngModule.component('vnHome', {
|
||||||
template: require('./home.html'),
|
template: require('./home.html'),
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Section from 'core/lib/section';
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Component {
|
||||||
constructor($el, $, $t, $http, $state) {
|
constructor($element, $) {
|
||||||
super($el, $, $t, $http, $state);
|
super($element, $);
|
||||||
this.nMonths = 4;
|
this.nMonths = 4;
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Section from 'core/lib/section';
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Component {
|
||||||
constructor($el, $, $t, $http, $state, $q, vnWeekDays) {
|
constructor($element, $, vnWeekDays) {
|
||||||
super($el, $, $t, $http, $state);
|
super($element, $);
|
||||||
this.$q = $q;
|
|
||||||
this.vnWeekDays = vnWeekDays;
|
this.vnWeekDays = vnWeekDays;
|
||||||
this.editMode = 'include';
|
this.editMode = 'include';
|
||||||
|
|
||||||
this.path = `api/Zones/${this.$stateParams.id}/events`;
|
this.path = `api/Zones/${this.$params.id}/events`;
|
||||||
this.exclusionsPath = `api/Zones/${this.$stateParams.id}/exclusions`;
|
this.exclusionsPath = `api/Zones/${this.$params.id}/exclusions`;
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +189,7 @@ class Controller extends Section {
|
||||||
.then(() => this.refresh());
|
.then(() => this.refresh());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$element', '$scope', '$translate', '$http', '$state', '$q', 'vnWeekDays'];
|
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
|
||||||
|
|
||||||
ngModule.component('vnZoneEvents', {
|
ngModule.component('vnZoneEvents', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="/api/Zones/{{$ctrl.$stateParams.id}}/getLeaves"
|
url="/api/Zones/{{$ctrl.$params.id}}/getLeaves"
|
||||||
filter="::$ctrl.filter">
|
filter="::$ctrl.filter">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div class="vn-w-md">
|
<div class="vn-w-md">
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Section from 'core/lib/section';
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Component {
|
||||||
onSearch(params) {
|
onSearch(params) {
|
||||||
this.$.model.applyFilter({}, params).then(() => {
|
this.$.model.applyFilter({}, params).then(() => {
|
||||||
const data = this.$.model.data;
|
const data = this.$.model.data;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Section from 'core/lib/section';
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Component {
|
||||||
constructor($el, $, $t, $http, $state) {
|
constructor($element, $) {
|
||||||
super($el, $, $t, $http, $state);
|
super($element, $);
|
||||||
|
|
||||||
this.path = `/api/Zones/${this.$stateParams.id}/warehouses`;
|
this.path = `/api/Zones/${this.$params.id}/warehouses`;
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller extends Component {
|
||||||
constructor($, vnApp, $translate, $http, $state, $stateParams) {
|
constructor($element, $) {
|
||||||
this.$state = $state;
|
super($element, $);
|
||||||
this.$stateParams = $stateParams;
|
|
||||||
this.$http = $http;
|
if (!this.$state.q) {
|
||||||
this.$ = $;
|
|
||||||
this.vnApp = vnApp;
|
|
||||||
this._ = $translate;
|
|
||||||
if (!$stateParams.q) {
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(23, 59, 59, 59);
|
today.setHours(23, 59, 59, 59);
|
||||||
|
|
||||||
|
@ -54,7 +51,7 @@ export default class Controller {
|
||||||
request.itemDescription = res.data.concept;
|
request.itemDescription = res.data.concept;
|
||||||
request.isOk = true;
|
request.isOk = true;
|
||||||
|
|
||||||
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +65,7 @@ export default class Controller {
|
||||||
let endpoint = `/api/Sales/${request.saleFk}/`;
|
let endpoint = `/api/Sales/${request.saleFk}/`;
|
||||||
|
|
||||||
this.$http.patch(endpoint, params).then(() => {
|
this.$http.patch(endpoint, params).then(() => {
|
||||||
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
}).then(() => this.confirmRequest(request));
|
}).then(() => this.confirmRequest(request));
|
||||||
} else
|
} else
|
||||||
this.confirmRequest(request);
|
this.confirmRequest(request);
|
||||||
|
@ -120,7 +117,7 @@ export default class Controller {
|
||||||
this.selectedRequest.attenderFk = request.attenderFk;
|
this.selectedRequest.attenderFk = request.attenderFk;
|
||||||
this.selectedRequest.response = request.response;
|
this.selectedRequest.response = request.response;
|
||||||
|
|
||||||
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
this.denyObservation = null;
|
this.denyObservation = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -154,8 +151,6 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http', '$state', '$stateParams'];
|
|
||||||
|
|
||||||
ngModule.component('vnItemRequest', {
|
ngModule.component('vnItemRequest', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller
|
controller: Controller
|
||||||
|
|
|
@ -4,6 +4,7 @@ import crudModel from 'core/mocks/crud-model';
|
||||||
describe('Item', () => {
|
describe('Item', () => {
|
||||||
describe('Component vnItemRequest', () => {
|
describe('Component vnItemRequest', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
|
let $element;
|
||||||
let controller;
|
let controller;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
|
|
||||||
|
@ -16,9 +17,15 @@ describe('Item', () => {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.model = crudModel;
|
$scope.model = crudModel;
|
||||||
$scope.denyReason = {hide: () => {}};
|
$scope.denyReason = {hide: () => {}};
|
||||||
controller = $componentController('vnItemRequest', {$scope: $scope});
|
$element = angular.element('<vn-item-request></vn-item-request>');
|
||||||
|
controller = $componentController('vnItemRequest', {$element, $scope});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
$scope.$destroy();
|
||||||
|
$element.remove();
|
||||||
|
});
|
||||||
|
|
||||||
describe('getState()', () => {
|
describe('getState()', () => {
|
||||||
it(`should return an string depending to the isOK value`, () => {
|
it(`should return an string depending to the isOK value`, () => {
|
||||||
let isOk = null;
|
let isOk = null;
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-submit label="Save"></vn-submit>
|
<vn-submit label="Save"></vn-submit>
|
||||||
<vn-button label="Undo changes" ng-if="$ctrl.$scope.form.$dirty" ng-click="watcher.loadOriginalData()"></vn-button>
|
<vn-button
|
||||||
|
label="Undo changes"
|
||||||
|
ng-if="form.$dirty"
|
||||||
|
ng-click="watcher.loadOriginalData()">
|
||||||
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,29 +1,21 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
class Controller {
|
class Controller extends Component {
|
||||||
constructor($scope, $http, vnApp, $translate) {
|
|
||||||
this.$scope = $scope;
|
|
||||||
this.$http = $http;
|
|
||||||
this.vnApp = vnApp;
|
|
||||||
this._ = $translate;
|
|
||||||
}
|
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const sip = this.worker.sip;
|
const sip = this.worker.sip;
|
||||||
const params = {
|
const params = {
|
||||||
userFk: this.worker.userFk,
|
userFk: this.worker.userFk,
|
||||||
extension: sip.extension
|
extension: sip.extension
|
||||||
};
|
};
|
||||||
this.$scope.watcher.check();
|
this.$.watcher.check();
|
||||||
this.$http.patch('/api/Sips', params).then(() => {
|
this.$http.patch('/api/Sips', params).then(() => {
|
||||||
this.$scope.watcher.updateOriginalData();
|
this.$.watcher.updateOriginalData();
|
||||||
this.vnApp.showSuccess(this._.instant('Data saved! User must access web'));
|
this.vnApp.showSuccess(this.$t('Data saved! User must access web'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
|
||||||
|
|
||||||
ngModule.component('vnWorkerPbx', {
|
ngModule.component('vnWorkerPbx', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
|
|
Loading…
Reference in New Issue