diff --git a/app/Api/V1/Controllers/User/PreferencesController.php b/app/Api/V1/Controllers/User/PreferencesController.php index 22d844014d..e947af858e 100644 --- a/app/Api/V1/Controllers/User/PreferencesController.php +++ b/app/Api/V1/Controllers/User/PreferencesController.php @@ -32,6 +32,7 @@ use FireflyIII\Models\Preference; use FireflyIII\Transformers\PreferenceTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Collection; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Resource\Collection as FractalCollection; use League\Fractal\Resource\Item; @@ -97,6 +98,32 @@ class PreferencesController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } + /** + * TODO This endpoint is not documented. + * + * Return a single preference by name. + */ + public function showList(Collection $collection): JsonResponse + { + $manager = $this->getManager(); + $count = $collection->count(); + $pageSize = $this->parameters->get('limit'); + $preferences = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); + + // make paginator: + $paginator = new LengthAwarePaginator($preferences, $count, $pageSize, $this->parameters->get('page')); + $paginator->setPath(route('api.v1.preferences.show-list').$this->buildParams()); + + /** @var PreferenceTransformer $transformer */ + $transformer = app(PreferenceTransformer::class); + $transformer->setParameters($this->parameters); + + $resource = new FractalCollection($preferences, $transformer, self::RESOURCE_KEY); + $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); + + return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); + } + /** * This endpoint is documented at: * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/preferences/storePreference diff --git a/resources/assets/v2/src/pages/accounts/index.js b/resources/assets/v2/src/pages/accounts/index.js index 05f1ace3d5..3444f23537 100644 --- a/resources/assets/v2/src/pages/accounts/index.js +++ b/resources/assets/v2/src/pages/accounts/index.js @@ -72,6 +72,12 @@ let index = function () { page: 1, filters: { active: 'both', + name: null, + }, + pageOptions: { + groupedAccounts: true, + sortingColumn: sortingColumn, + sortDirection: sortDirection, }, // available columns: @@ -131,8 +137,6 @@ let index = function () { }, }, editors: {}, - sortingColumn: sortingColumn, - sortDirection: sortDirection, accounts: [], accountRole(roleName) { @@ -140,12 +144,20 @@ let index = function () { }, sort(column) { - this.sortingColumn = column; - this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc'; - const url = './accounts/' + type + '?column=' + column + '&direction=' + this.sortDirection; + this.pageOptions.sortingColumn = column; + this.pageOptions.sortDirection = this.pageOptions.sortDirection === 'asc' ? 'desc' : 'asc'; + const url = './accounts/' + type + '?column=' + column + '&direction=' + this.pageOptions.sortDirection; window.history.pushState({}, "", url); + // get sort column + // TODO variable name in better place + const columnKey = 'acc_index_' + type + '_sc'; + const directionKey = 'acc_index_' + type + '_sd'; + + setVariable(columnKey, this.pageOptions.sortingColumn); + setVariable(directionKey, this.pageOptions.sortDirection); + this.loadAccounts(); return false; }, @@ -165,23 +177,53 @@ let index = function () { } } console.log('New settings', newSettings); - setVariable('accts_columns_' + type, newSettings); + setVariable('acc_index_' + type + '_columns', newSettings); }, init() { this.notifications.wait.show = true; - this.notifications.wait.text = i18next.t('firefly.wait_loading_data') + this.notifications.wait.text = i18next.t('firefly.wait_loading_data'); - const key = 'accts_columns_' + type; + // get column preference + // TODO key in better variable + const key = 'acc_index_' + type + '_columns'; const defaultValue = {"drag_and_drop": false}; + // get sort column + const columnKey = 'acc_index_' + type + '_sc'; + const columnDefault = ''; + + // get sort direction + const directionKey = 'acc_index_' + type + '_sd'; + const directionDefault = ''; + + getVariable(key, defaultValue).then((response) => { for (let k in response) { if (response.hasOwnProperty(k) && this.tableColumns.hasOwnProperty(k)) { this.tableColumns[k].enabled = response[k] ?? true; } } - }).then(() => { + }). + // get sorting preference, and overrule it if is not "" twice + then(() => { + return getVariable(columnKey, columnDefault).then((response) => { + console.log('Sorting column is "' + response + '"'); + this.pageOptions.sortingColumn = '' === this.pageOptions.sortingColumn ? response : this.pageOptions.sortingColumn; + }) + }) + . + // get sorting preference, and overrule it if is not "" twice + then(() => { + return getVariable(directionKey, directionDefault).then((response) => { + console.log('Sorting direction is "' + response + '"'); + this.pageOptions.sortDirection = '' === this.pageOptions.sortDirection ? response : this.pageOptions.sortDirection; + }) + }). + + + + then(() => { this.loadAccounts(); }); @@ -230,7 +272,7 @@ let index = function () { loadAccounts() { // sort instructions - const sorting = [{column: this.sortingColumn, direction: this.sortDirection}]; + const sorting = [{column: this.pageOptions.sortingColumn, direction: this.pageOptions.sortDirection}]; // get start and end from the store: const start = new Date(window.store.get('start')); diff --git a/resources/assets/v2/src/store/get-variable.js b/resources/assets/v2/src/store/get-variable.js index f65e474b7e..f0bb1b26b7 100644 --- a/resources/assets/v2/src/store/get-variable.js +++ b/resources/assets/v2/src/store/get-variable.js @@ -39,6 +39,10 @@ export function getVariable(name, defaultValue = null) { return getter.getByName(name).then((response) => { return Promise.resolve(parseResponse(name, response)); }).catch((error) => { + if('' === defaultValue) { + // do not try to store empty strings. + return Promise.resolve(defaultValue); + } // preference does not exist (yet). // POST it and then return it anyway. let poster = (new Post); diff --git a/resources/views/v2/accounts/index.blade.php b/resources/views/v2/accounts/index.blade.php index b4ef54be97..0704791ba3 100644 --- a/resources/views/v2/accounts/index.blade.php +++ b/resources/views/v2/accounts/index.blade.php @@ -59,68 +59,103 @@   - - Active? - - - +   - Name - - + "Filtered" - Type +   - Liability type +   - Liability direction +   - Liability interest +   - Account number - - +   - Current balance - - +   - Amount due - - +   - Last activity - - +   - Balance - difference - - +     + + +   + + + Active? + + + + + Name + + + + Type + + Liability type + + + Liability direction + + + Liability interest + + + Account number + + + + + Current balance + + + + + Amount due + + + + + Last activity + + + + + Balance + difference + + + +   +