Skip to content
Snippets Groups Projects
Commit 8bf938ca authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #42 add plugin for paginate language table + add autocomplete plugin

parent e1ee08e8
Branches
Tags
No related merge requests found
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var material_1 = require("@angular/material");
var frenchRangeLabel = function (page, pageSize, length) {
if (length == 0 || pageSize == 0) {
return "0 de " + length;
}
length = Math.max(length, 0);
var startIndex = page * pageSize;
// If the start index exceeds the list length, do not try and fix the end index to the end.
var endIndex = startIndex < length ?
Math.min(startIndex + pageSize, length) :
startIndex + pageSize;
var nbPage = Math.ceil(length / pageSize);
//return `${startIndex + 1} - ${endIndex} / ${length} (${page})`;
return "Page " + (page + 1) + " / " + nbPage;
};
function getFrenchPaginatorIntl() {
var paginatorIntl = new material_1.MatPaginatorIntl();
paginatorIntl.itemsPerPageLabel = 'Afficher:';
paginatorIntl.nextPageLabel = 'Page suivante';
paginatorIntl.previousPageLabel = 'Page précédente';
paginatorIntl.getRangeLabel = frenchRangeLabel;
return paginatorIntl;
}
exports.getFrenchPaginatorIntl = getFrenchPaginatorIntl;
import {MatPaginatorIntl} from '@angular/material';
const frenchRangeLabel = (page: number, pageSize: number, length: number) => {
if (length == 0 || pageSize == 0) { return `0 de ${length}`; }
length = Math.max(length, 0);
const startIndex = page * pageSize;
// If the start index exceeds the list length, do not try and fix the end index to the end.
const endIndex = startIndex < length ?
Math.min(startIndex + pageSize, length) :
startIndex + pageSize;
const nbPage = Math.ceil(length / pageSize);
//return `${startIndex + 1} - ${endIndex} / ${length} (${page})`;
return `Page ${page + 1} / ${nbPage}`;
}
export function getFrenchPaginatorIntl() {
const paginatorIntl = new MatPaginatorIntl();
paginatorIntl.itemsPerPageLabel = 'Afficher:';
paginatorIntl.nextPageLabel = 'Page suivante';
paginatorIntl.previousPageLabel = 'Page précédente';
paginatorIntl.getRangeLabel = frenchRangeLabel;
return paginatorIntl;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var forms_1 = require("@angular/forms");
var startWith_1 = require("rxjs/operators/startWith");
var map_1 = require("rxjs/operators/map");
var AutoCompletePlugin = /** @class */ (function () {
function AutoCompletePlugin(http, target) {
var _this = this;
this.http = http;
this.userList = [];
this.coreUrl = angularGlobals.coreUrl;
this.userCtrl = new forms_1.FormControl();
if (target == 'users') {
this.http.get(this.coreUrl + 'rest/users/autocompleter')
.subscribe(function (data) {
_this.userList = data;
}, function () {
location.href = "index.php";
});
}
else {
}
this.filteredUsers = this.userCtrl.valueChanges
.pipe(startWith_1.startWith(''), map_1.map(function (user) { return user ? _this.autocompleteFilter(user) : _this.userList.slice(); }));
}
AutoCompletePlugin.prototype.autocompleteFilter = function (name) {
return this.userList.filter(function (user) {
return user.formattedUser.toLowerCase().indexOf(name.toLowerCase()) === 0;
});
};
return AutoCompletePlugin;
}());
exports.AutoCompletePlugin = AutoCompletePlugin;
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
import { startWith } from 'rxjs/operators/startWith';
import { map } from 'rxjs/operators/map';
declare const angularGlobals: any;
export class AutoCompletePlugin {
coreUrl: string;
userCtrl: FormControl;
filteredUsers: Observable<any[]>;
userList: any[] = [];
constructor(public http: HttpClient, target:any) {
this.coreUrl = angularGlobals.coreUrl;
this.userCtrl = new FormControl();
if (target == 'users') {
this.http.get(this.coreUrl + 'rest/users/autocompleter')
.subscribe((data: any) => {
this.userList = data;
}, () => {
location.href = "index.php";
});
} else {
}
this.filteredUsers = this.userCtrl.valueChanges
.pipe(
startWith(''),
map(user => user ? this.autocompleteFilter(user) : this.userList.slice())
);
}
autocompleteFilter(name: string) {
return this.userList.filter(user =>
user.formattedUser.toLowerCase().indexOf(name.toLowerCase()) === 0);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment