Skip to content

Instantly share code, notes, and snippets.

@argentinaluiz
Created January 2, 2020 17:47
Show Gist options
  • Save argentinaluiz/8e0441d026b4cd837bc46d56779207c4 to your computer and use it in GitHub Desktop.
Save argentinaluiz/8e0441d026b4cd837bc46d56779207c4 to your computer and use it in GitHub Desktop.
tradução do mui-datatables e http resource
import {AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelTokenSource} from "axios";
import axios from 'axios';
export default class HttpResource {
private cancelList: CancelTokenSource | null = null;
constructor(protected http: AxiosInstance, protected resource) {
}
list<T = any>(options?: { queryParams? }): Promise<AxiosResponse<T>> {
if (this.cancelList) {
this.cancelList.cancel('list request cancelled');
}
this.cancelList = axios.CancelToken.source();
const config: AxiosRequestConfig = {
cancelToken: this.cancelList.token
};
if (options && options.queryParams) {
config.params = options.queryParams
}
return this.http.get<T>(this.resource, config);
}
get<T = any>(id): Promise<AxiosResponse<T>> {
return this.http.get<T>(`${this.resource}/${id}`);
}
create<T = any>(data): Promise<AxiosResponse<T>> {
return this.http.post<T>(this.resource, data);
}
update<T = any>(id, data): Promise<AxiosResponse<T>> {
return this.http.put<T>(`${this.resource}/${id}`, data);
}
delete<T = any>(id): Promise<AxiosResponse<T>> {
return this.http.delete<T>(`${this.resource}/${id}`);
}
isCancelledRequest(error){
return axios.isCancel(error);
}
}
{
print: false,
download: false,
textLabels: {
body: {
noMatch: "Nenhum registro encontrado",
toolTip: "Classificar",
},
pagination: {
next: "Próxima página",
previous: "Página anterior",
rowsPerPage: "Por página:",
displayRows: "de",
},
toolbar: {
search: "Busca",
downloadCsv: "Download CSV",
print: "Imprimir",
viewColumns: "Ver Colunas",
filterTable: "Filtrar Tabelas",
},
filter: {
all: "Todos",
title: "FILTROS",
reset: "LIMPAR",
},
viewColumns: {
title: "Ver Colunas",
titleAria: "Ver/Esconder Colunas da Tabela",
},
selectedRows: {
text: "registros(s) selecionados",
delete: "Excluir",
deleteAria: "Excluir registros selecionados",
},
},
customSearchRender: (searchText: string,
handleSearch: any,
hideSearch: any,
options: any) => {
return <DebouncedTableSearch
searchText={searchText}
onSearch={handleSearch}
onHide={hideSearch}
options={options}
debounceTime={debouncedSearchTime}
/>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment