ModelProxy.status, Paging removed, locale fixes
gitea/salix/dev This commit looks good Details

This commit is contained in:
Juan Ferrer 2019-10-03 19:34:24 +02:00
parent a8f2000f3f
commit c6e8498281
20 changed files with 60 additions and 228 deletions

View File

@ -207,8 +207,8 @@ export default class CrudModel extends ModelProxy {
sendRequest(filter, append) {
this.cancelRequest();
this.canceler = this.$q.defer();
this.isRefreshing = !append;
this.isPaging = append;
if (!append) this.status = 'loading';
let params = Object.assign(
{filter},
@ -221,9 +221,8 @@ export default class CrudModel extends ModelProxy {
return this.$http.get(this._url, options).then(
json => this.onRemoteDone(json, filter, append),
json => this.onRemoteError(json)
json => this.onRemoteError(json, append)
).finally(() => {
this.isRefreshing = false;
this.isPaging = false;
});
}
@ -243,7 +242,12 @@ export default class CrudModel extends ModelProxy {
this.onRequestEnd();
}
onRemoteError(err) {
onRemoteError(err, append) {
if (!append) {
this.clear();
this.status = 'error';
}
this.onRequestEnd();
throw err;
}

View File

@ -1,22 +1,28 @@
<div ng-if="$ctrl.hasData">
<div ng-if="$ctrl.isReady">
<div ng-transclude></div>
<vn-pagination
model="$ctrl.model">
model="$ctrl.model"
pad-medium-top>
</vn-pagination>
</div>
<div
class="empty-rows"
ng-if="!$ctrl.hasData"
ng-if="!$ctrl.isReady"
ng-switch="$ctrl.status">
<vn-spinner
ng-switch-when="loading"
enable="true">
enable="::true">
</vn-spinner>
<span
ng-switch-when="clear"
translate>
Enter a new search
</span>
<span
ng-switch-when="error"
translate>
Ups! It seems there was an error
</span>
<span
ng-switch-when="empty"
translate>

View File

@ -2,28 +2,22 @@ import ngModule from '../../module';
import './style.scss';
export default class DataViewer {
get computedData() {
return this.data || (this.model && this.model.data);
}
get computedLoading() {
return this.isLoading || (this.model && this.model.isRefreshing);
}
get hasData() {
let data = this.computedData;
return data && data.length;
get isReady() {
return this.status == 'ready';
}
get status() {
if (this.hasData)
return null;
if (this.computedLoading)
if (this.model)
return this.model.status;
if (this.isLoading)
return 'loading';
if (this.computedData)
return 'empty';
else
if (!this.data)
return 'clear';
if (this.data.length)
return 'ready';
else
return 'empty';
}
}

View File

@ -26,7 +26,6 @@ import './card/card';
import './float-button/float-button';
import './step-control/step-control';
import './label-value/label-value';
import './paging/paging';
import './pagination/pagination';
import './searchbar/searchbar';
import './scroll-up/scroll-up';

View File

@ -57,6 +57,7 @@ export default class ModelProxy extends DataModel {
constructor($element, $scope) {
super($element, $scope);
this.resetChanges();
this.status = 'clear';
}
get orgData() {
@ -90,6 +91,14 @@ export default class ModelProxy extends DataModel {
set data(value) {
this._data = value;
if (value == null)
this.status = 'clear';
else if (value.length)
this.status = 'ready';
else
this.status = 'empty';
this.emit('dataChange');
this.emit('dataUpdate');
}
@ -109,8 +118,12 @@ export default class ModelProxy extends DataModel {
this.removed.push(item);
this.isChanged = true;
if (!this.data.length)
this.status = 'empty';
this.emit('rowRemove', index);
this.emit('dataUpdate');
if (this.autoSave)
this.save();
}
@ -131,8 +144,11 @@ export default class ModelProxy extends DataModel {
this.data.push(newRow);
this.isChanged = true;
this.status = 'ready';
this.emit('rowInsert', index);
this.emit('dataUpdate');
return index;
}
@ -322,10 +338,10 @@ export class Paginable {
}
/**
* @type {Boolean} Whether the model is refreshing.
* @type {ready|loading|clear|empty|error} The current model status.
*/
get isRefreshing() {
return false;
get status() {
return null;
}
/**

View File

@ -1,13 +1,12 @@
<div
ng-if="$ctrl.model.moreRows">
<div ng-if="$ctrl.model.moreRows">
<vn-icon-button
ng-if="!$ctrl.model.isLoading"
ng-if="!$ctrl.model.isPaging"
icon="more_horiz"
vn-tooltip="Load more"
ng-click="$ctrl.onLoadClick()">
</vn-icon-button>
<vn-spinner
ng-if="$ctrl.model.isLoading"
enable="$ctrl.model.isLoading">
ng-if="$ctrl.model.isPaging"
enable="::true">
</vn-spinner>
</div>

View File

@ -3,7 +3,8 @@ vn-pagination {
display: block;
text-align: center;
& > div > vn-icon-button {
& > div > vn-icon-button {
font-size: 2em;
padding: 0;
}
}

View File

@ -1,11 +0,0 @@
<paging
page="$ctrl.currentPage"
page-size="$ctrl.numPerPage"
ng-if="$ctrl.numPages>1"
total="$ctrl.numItems"
show-prev-next="true"
show-first-last="false"
active-class="active"
ng-click="$ctrl.figureOutToDisplay()"
paging-action="$ctrl.onPageChange(page)">
</paging>

View File

@ -1,58 +0,0 @@
import ngModule from '../../module';
import './style.scss';
export default class Paging {
get numPages() {
return Math.ceil(this.numItems / this.numPerPage);
}
constructor($http, $scope) {
this.$http = $http;
this.$scope = $scope;
this.where = this.filter;
this.numPerPage = null;
this.numItems = 0;
$scope.$watch('$ctrl.index.model.length', () => this.onModelUpdated());
}
$onChanges(changes) {
if (!this.index) return;
this.numPerPage = this.index.filter.size;
this.currentPage = this.index.filter.page;
if (changes.total)
this.numItems = changes.total.currentValue;
}
onModelUpdated() {
let index = this.index;
let filter = index.filter;
if (filter.page >= this.numPages && index.model.length >= this.numPerPage)
this.numItems = filter.page * filter.size + 1;
}
onPageChange(page) {
this.index.filter.page = page;
if (typeof this.pageChange === 'undefined') {
this.index.accept();
} else {
this.pageChange();
}
}
$doCheck() {
if (this.index && this.index.filter && this.index.filter.page && this.index.filter.page != this.currentPage) {
this.currentPage = this.index.filter.page;
}
}
}
Paging.$inject = ['$http', '$scope'];
ngModule.component('vnPaging', {
template: require('./paging.html'),
bindings: {
index: '<',
pageChange: '&?',
total: '<'
},
controller: Paging
});

View File

@ -1,65 +0,0 @@
import './paging.js';
describe('Component vnPaging', () => {
let $scope;
let controller;
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
controller = $componentController('vnPaging', {$scope});
}));
describe('$onChanges()', () => {
it(`should define numberPage and currentPage based on index.filter properties`, () => {
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({index: 'simpleChange', currentValue: 'current value', previousValue: 'previous value'});
expect(controller.numPerPage).toBe(controller.index.filter.size);
expect(controller.currentPage).toEqual(controller.index.filter.page);
});
it(`should define numItems based on changes.total.currentValue`, () => {
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({total: {currentValue: 'current value'}});
expect(controller.numItems).toEqual('current value');
});
});
describe('onModelUpdated()', () => {
it(`should define controllers numItems as the result of page times size plus one`, () => {
controller.numPerPage = 2;
controller.index = {
filter: {size: 10, page: 10},
model: ['one mother..', 'another model..', 'last model..']
};
controller.onModelUpdated();
expect(controller.numItems).toBe(101);
});
});
describe('onPageChange()', () => {
it(`should call accept() since pageChange property is undefined`, () => {
controller.index = {accept: () => {}, filter: {page: 0}};
spyOn(controller.index, 'accept');
controller.onPageChange(100);
expect(controller.index.accept).toHaveBeenCalledWith();
});
it(`should call pageChange() since pageChange property isn't undefined`, () => {
controller.index = {accept: () => {}, filter: {page: 0}};
controller.pageChange = true;
spyOn(controller, 'pageChange');
controller.onPageChange(100);
expect(controller.pageChange).toHaveBeenCalledWith();
});
});
});

View File

@ -1,40 +0,0 @@
@import "variables";
vn-paging {
display: block;
text-align: center;
ul {
box-shadow: 0 0 .4em $color-shadow;
background-color: #fff;
display: inline-block;
margin: 20px 0;
border-radius: .1em;
padding: 0;
}
li {
display: inline;
&:first-child > a,
&:first-child > span {
margin-left: 0;
}
&.active > a {
background: $color-active;
color: #fff;
}
& > a,
& > span {
position: relative;
float: left;
padding: 6px 12px;
margin-left: -1px;
line-height: 1.42857143;
color: inherit;
text-decoration: none;
}
&:not(.active) > a:hover {
background-color: #ddd;
}
}
}

View File

@ -180,11 +180,8 @@ export default class Popover extends Component {
onDocKeyDown(event) {
if (event.defaultPrevented) return;
if (event.keyCode == 27) { // Esc
event.preventDefault();
if (event.code == 'Escape')
this.hide();
}
}
onMouseDown(event) {

View File

@ -24,6 +24,9 @@ Value should be %s characters long: El valor debe ser de %s carácteres de longi
Value should have a length between %s and %s: El valor debe tener una longitud de entre %s y %s
Value should have at least %s characters: El valor debe tener al menos %s carácteres
Value should have at most %s characters: El valor debe tener un máximo de %s carácteres
Enter a new search: Introduce una nueva búsqueda
No results: Sin resultados
Ups! It seems there was an error: ¡Vaya! Parece que ha habido un error
General search: Busqueda general
January: Enero
February: Febrero

View File

@ -7,10 +7,6 @@ import 'angular-translate-loader-partial';
import '@uirouter/angularjs';
import 'mg-crud';
import 'oclazyload';
/*
import 'angular-material';
import 'angular-material/modules/scss/angular-material.scss';
*/
import 'angular-moment';
export const ngDeps = [
@ -18,7 +14,6 @@ export const ngDeps = [
'ui.router',
'mgCrud',
'oc.lazyLoad',
// 'ngMaterial',
'angularMoment'
];

View File

@ -14,8 +14,6 @@ Push on applications menu: Para abrir un módulo pulsa en el menú de aplicacion
Return to module index: Volver a la página principal del módulo
What is new: Novedades de la versión
Settings: Ajustes
Enter a new search: Introduce una nueva búsqueda
No results: Sin resultados
# Actions

View File

@ -1,3 +1,2 @@
Since : Desde
Employee : Empleado
No results: Sin resultados
Employee : Empleado

View File

@ -1,5 +1,4 @@
Since: Desde
Employee: Empleado
No results: Sin resultados
To: Hasta
Finish that recovery period: Terminar el recobro

View File

@ -33,8 +33,6 @@ Remove niche: Quitar nicho
Add barcode: Añadir código de barras
Remove barcode: Quitar código de barras
Buyer: Comprador
No results: Sin resultados
Enter a new search: Introduce una nueva búsqueda
Tag: Etiqueta
Worker: Trabajador
Available: Disponible

View File

@ -131,7 +131,7 @@ class Controller {
}
get isRefreshing() {
return this.$scope.model && this.$scope.model.isRefreshing;
return this.$scope.model && this.$scope.model.status == 'loading';
}
}

View File

@ -3,8 +3,6 @@ Catalog: Catálogo
from: desde
results: resultados
More than: Más de
No results: Sin resultados
Enter a new search: Introduce una nueva búsqueda
Plant: Planta
Flower: Flor
Handmade: Confección