2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-06 16:47:59 +02:00
|
|
|
import { alt } from '../alt';
|
2015-07-24 13:44:28 +02:00
|
|
|
import Q from 'q';
|
2015-05-21 17:59:38 +02:00
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
|
|
|
|
2015-08-06 18:03:13 +02:00
|
|
|
|
2015-10-12 13:57:37 +02:00
|
|
|
class PieceListActions {
|
|
|
|
constructor() {
|
2015-05-19 17:13:09 +02:00
|
|
|
this.generateActions(
|
2015-07-01 19:05:47 +02:00
|
|
|
'updatePieceList',
|
2015-07-09 15:44:20 +02:00
|
|
|
'updatePieceListRequestActions',
|
2015-07-10 13:54:25 +02:00
|
|
|
'updatePropertyForPiece'
|
2015-05-19 17:13:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:39:33 +02:00
|
|
|
fetchPieceList(page, pageSize, search, orderBy, orderAsc, filterBy) {
|
2015-07-13 19:12:24 +02:00
|
|
|
// To prevent flickering on a pagination request,
|
|
|
|
// we overwrite the piecelist with an empty list before
|
|
|
|
// pieceListCount === -1 defines the loading state
|
|
|
|
this.actions.updatePieceList({
|
|
|
|
page,
|
|
|
|
pageSize,
|
|
|
|
orderBy,
|
|
|
|
orderAsc,
|
2015-08-04 11:39:33 +02:00
|
|
|
filterBy,
|
2015-10-12 16:38:00 +02:00
|
|
|
search: '',
|
2015-08-31 16:57:16 +02:00
|
|
|
pieceList: [],
|
|
|
|
pieceListCount: -1,
|
|
|
|
unfilteredPieceListCount: -1
|
2015-07-13 19:12:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// afterwards, we can load the list
|
2015-07-24 13:44:28 +02:00
|
|
|
return Q.Promise((resolve, reject) => {
|
2015-07-01 19:05:47 +02:00
|
|
|
PieceListFetcher
|
2015-08-04 11:39:33 +02:00
|
|
|
.fetch(page, pageSize, search, orderBy, orderAsc, filterBy)
|
2015-07-01 19:05:47 +02:00
|
|
|
.then((res) => {
|
|
|
|
this.actions.updatePieceList({
|
|
|
|
page,
|
|
|
|
pageSize,
|
|
|
|
search,
|
|
|
|
orderBy,
|
|
|
|
orderAsc,
|
2015-08-04 11:39:33 +02:00
|
|
|
filterBy,
|
2015-08-31 16:57:16 +02:00
|
|
|
pieceList: res.pieces,
|
|
|
|
pieceListCount: res.count,
|
|
|
|
unfilteredPieceListCount: res.unfiltered_count
|
2015-07-01 19:05:47 +02:00
|
|
|
});
|
|
|
|
resolve();
|
2015-07-07 09:22:46 +02:00
|
|
|
})
|
|
|
|
.catch((err) => reject(err));
|
2015-07-01 19:05:47 +02:00
|
|
|
});
|
|
|
|
}
|
2015-07-09 15:44:20 +02:00
|
|
|
|
2015-07-01 19:05:47 +02:00
|
|
|
fetchPieceRequestActions() {
|
2015-05-21 17:59:38 +02:00
|
|
|
PieceListFetcher
|
2015-07-01 19:05:47 +02:00
|
|
|
.fetchRequestActions()
|
2015-05-19 17:13:09 +02:00
|
|
|
.then((res) => {
|
2015-08-28 15:24:32 +02:00
|
|
|
this.actions.updatePieceListRequestActions(res);
|
2015-07-17 15:41:09 +02:00
|
|
|
})
|
|
|
|
.catch((err) => console.logGlobal(err));
|
2015-05-19 17:13:09 +02:00
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
}
|
2015-05-19 17:13:09 +02:00
|
|
|
|
|
|
|
export default alt.createActions(PieceListActions);
|