Skip to content

Commit

Permalink
Adding ember cli release and ember changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerac4 committed Apr 3, 2019
1 parent 8d9fbaf commit 245a5c1
Show file tree
Hide file tree
Showing 10 changed files with 2,374 additions and 118 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changelog
=========

## 0.0.0

- Hold Your Horses,
- Pack Your Parachutes,
- We're Coming,
- But we haven't released anything yet.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
gavant-pagination
==============================================================================

[Short description of the addon.]

DISCLAIMER: This addon is not actively maintained for public use. Pull requests are welcome, but we do not guarantee responses to bug submissions or feature requests, so use at your own risk.

Compatibility
------------------------------------------------------------------------------
Expand All @@ -22,8 +21,49 @@ ember install gavant-pagination
Usage
------------------------------------------------------------------------------

[Longer description of how to use the addon in apps.]
There are two ways to use this addon.

For classic classes, you use the mixin.

```
import Route from '@ember/routing/route';
import RoutePagination from 'gavant-pagination/mixins/route-pagination';
export default Route.extend(RoutePagination, {
model() {
const params = this.getControllerParams();
return get(this, 'store').query('account', params);
}
});
```

For Native classes, you use the "decorator".
```
import Route from '@ember/routing/route';
import RoutePagination from 'gavant-pagination/decorators/route-pagination';
export default class Accounts extends RoutePagination(Route) {
model() {
const params = this.getControllerParams();
return this.store.query('account', params);
}
}
```

Technically speaking you can actually use the route-pagination as a decorator..
```
import Route from '@ember/routing/route';
import RoutePagination from 'gavant-pagination/decorators/route-pagination';
@RoutePagination
export default class Accounts extends Route {
model() {
const params = this.getControllerParams();
return this.store.query('account', params);
}
}
```
but the main issue with that is RoutePagination will be the extend the `Accounts` Route, and generally you want the order of that to be reversed.

Contributing
------------------------------------------------------------------------------
Expand Down
15 changes: 5 additions & 10 deletions addon/decorators/controller-pagination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DS from 'ember-data';
import { RouteParams, buildQueryParams } from 'gavant-pagination/utils/query-params';
import { RouteParams, buildQueryParams, sortDirection } from 'gavant-pagination/utils/query-params';
import { tryInvoke } from '@ember/utils';
import { reject } from 'rsvp';
import { A } from '@ember/array';
Expand All @@ -9,11 +9,6 @@ import { readOnly, or } from '@ember-decorators/object/computed';
import { inject as service } from '@ember-decorators/service';
import Router from '@ember/routing/router-service';

export enum sortDirection {
ascending = "asc",
descending = "desc"
}

/**
* Adds functionality to `setupController` / `resetController`. Be sure to call `super` in the respective methods to ensure this runs
* @param Controller - The controller you want the functionality to be added on to
Expand All @@ -30,7 +25,7 @@ export default function controllerPagination<T extends ConcreteSubclass<any>>(Co
serverQueryParams: any;
isLoadingPage = false;

@or('loadModelsTask.isRunning', 'isLoadingRoute') isLoadingModels!: boolean;
@or('isLoadingPage', 'isLoadingRoute') isLoadingModels!: boolean;
@readOnly('model.length') offset: number | undefined;

@computed('router.currentRouteName')
Expand All @@ -44,7 +39,7 @@ export default function controllerPagination<T extends ConcreteSubclass<any>>(Co
}

async _loadModels(this: PaginationController, reset: boolean, params: RouteParams | undefined) {
this.isLoadingPage = true;
this.set('isLoadingPage', true);
if(reset) {
this.clearModels();
}
Expand All @@ -58,14 +53,14 @@ export default function controllerPagination<T extends ConcreteSubclass<any>>(Co
models = result.toArray();

this.metadata = result.meta;
this.hasMore = models.length >= limit;
this.set('hasMore', models.length >= limit);

tryInvoke(this.model, 'pushObjects', [models]);
} catch(errors) {
reject(errors);
}

this.isLoadingPage = false;
this.set('isLoadingPage', false);
return models;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import { get, set, setProperties } from '@ember/object';
import { get, set, setProperties, computed } from '@ember/object';
import { readOnly, or } from '@ember/object/computed';
import { tryInvoke } from '@ember/utils';
import { reject } from 'rsvp';
import { A } from '@ember/array';
import { math, divide, string, bool } from 'ember-awesome-macros';
import { buildQueryParams } from 'gavant-pagination/utils/query-params';
import { buildQueryParams, PaginationController, RouteParams, sortDirection } from 'gavant-pagination/utils/query-params';

export default Mixin.create({
router: service(),
Expand All @@ -16,13 +15,17 @@ export default Mixin.create({
limit: 10,
isLoadingPage: false,

isLoadingRoute: bool(string.match('router.currentRouteName', /loading$/)),
isLoadingModels: or('loadModelsTask.isRunning', 'isLoadingRoute'),
isLoadingRoute: computed('router.currentRouteName', function() {
return get(this, 'router.currentRouteName').match(/loading$/);
}),
isLoadingModels: or('isLoadingPage', 'isLoadingRoute'),
offset: readOnly('model.length'),
pagesLoaded: math.ceil(divide('model.length', 'limit')),
pagesLoaded: computed('model.length', 'limit', function() {
return Math.ceil(get(this, 'model.length') / get(this, 'limit'));
}),

async _loadModels(reset, params) {
this.isLoadingPage = true;
async _loadModels(this: PaginationController, reset: boolean, params: RouteParams | undefined) {
set(this, 'isLoadingPage', true);
if(reset) {
this.clearModels();
}
Expand All @@ -44,7 +47,7 @@ export default Mixin.create({
} catch(errors) {
reject(errors);
}

set(this, 'isLoadingPage', false);
return models;
},

Expand Down Expand Up @@ -72,32 +75,32 @@ export default Mixin.create({

//override this method if more complex logic is necessary to retrieve the records
//it should return a promise, which resolves to an array-like object (such as a DS.RecordArray)
fetchModels(queryParams) {
fetchModels(this: PaginationController, queryParams: any) {
const modelName = get(this, 'modelName');
return get(this, 'store').query(modelName, queryParams);
},

loadModels(reset, params) {
loadModels(this: PaginationController, reset: boolean, params: RouteParams) {
if (!get(this, 'isLoadingPage')) {
return this._loadModels(reset, params);
} else {
return;
}
},

clearModels() {
clearModels(this: PaginationController) {
set(this, 'model', A());
},

reloadModels() {
reloadModels(this: PaginationController) {
return this.loadModels(true);
},

loadMoreModels() {
loadMoreModels(this: PaginationController) {
return this.loadModels();
},

async removeModel(row) {
async removeModel(this: PaginationController, row: any) {
try {
let model = get(row, 'content');
let result = await tryInvoke(model, 'destroyRecord');
Expand All @@ -108,7 +111,7 @@ export default Mixin.create({
}
},

changeSorting(sort, dir, isSorted) {
changeSorting(this: PaginationController, sort: string[], dir: sortDirection, isSorted: boolean) {
const sorting = get(this, 'sort');
const sortedValue = `${dir === "desc" ? '-' : ''}${sort}`;
const oppositeSortedValue = `${dir === "asc" ? '-' : ''}${sort}`;
Expand All @@ -126,12 +129,12 @@ export default Mixin.create({
return this.filterModels();
},

filterModels() {
filterModels(this: PaginationController) {
return this.loadModels(true);
},

clearFilters() {
get(this, 'serverQueryParams').forEach((param) => set(this, param, null));
clearFilters(this: PaginationController) {
get(this, 'serverQueryParams').forEach((param: any) => set(this, param, null));
return this.filterModels();
},

Expand All @@ -140,30 +143,30 @@ export default Mixin.create({
},

actions: {
loadMoreModels() {
loadMoreModels(this: PaginationController) {
return this.loadMoreModels();
},

reloadModels() {
reloadModels(this: PaginationController) {
return this.reloadModels();
},

removeModel(row) {
removeModel(this: PaginationController, row: any) {
return this.removeModel(row);
},

clearModels() {
clearModels(this: PaginationController) {
this.clearModels();
},

filter() {
filter(this: PaginationController) {
return this.filterModels();
},

changeSorting(sort, dir, isSorted) {
changeSorting(this: PaginationController, sort: string[], dir: sortDirection, isSorted: boolean) {
return this.changeSorting(sort, dir, isSorted);
},
clearFilters() {
clearFilters(this: PaginationController) {
return this.clearFilters();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Mixin from '@ember/object/mixin';
import { get, set, setProperties } from '@ember/object';
import { assert } from '@ember/debug';
import DS from 'ember-data';
import { PaginationController, buildQueryParams } from 'gavant-pagination/utils/query-params';

export default Mixin.create({
shoeboxRouteEnabled: false,

setupController(controller, model) {
setupController(controller: PaginationController, model: any) {
assert('Model is not an instanceof DS.AdapterPopulatedRecordArray. In order to use the RoutePaginationMixin, the model returned must be an instance of DS.AdapterPopulatedRecordArray which comes from using store.query', model instanceof DS.AdapterPopulatedRecordArray);
setProperties(controller, {
modelName: get(model, 'type.modelName'),
Expand All @@ -18,13 +17,12 @@ export default Mixin.create({
this._super(controller, model);
},

getControllerParams() {
const routeName = this.routeName;
getControllerParams(this: PaginationController, routeName = this.routeName): any {
const controller = this.controllerFor(routeName);
return this.buildQueryParams(controller);
return buildQueryParams(controller);
},

resetController(controller, isExiting) {
resetController(controller: PaginationController, isExiting: boolean) {
this._super.apply(this, arguments);

if (isExiting) {
Expand Down
5 changes: 5 additions & 0 deletions addon/utils/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface PaginationController {
[key: string]: any;
}

export enum sortDirection {
ascending = "asc",
descending = "desc"
}

/**
* Builds the query params to send to the server by taking the controller, route params, and paging data(`offset` & `limit`)
* @param controller The pagination controller instance
Expand Down
23 changes: 23 additions & 0 deletions config/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// jshint node:true

// For details on each option run `ember help release`
module.exports = {

// angular style guide: https://github.com/angular/angular.js/blob/v1.4.8/CONTRIBUTING.md#commit
// jquery style guide: https://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines
// ember style guide: https://github.com/emberjs/ember.js/blob/master/CONTRIBUTING.md#commit-tagging
style: 'angular', // 'ember' 'jquery'

head: 'master',
base: '-last', // a branch or tag name, `-last` defaults to the version in package.json

hooks: {
/*
parser: function(commit) { return commit; }
filter: function(commit) { return true; },
groupSort: function(commits) { return { commits: commits }; },
format: function(commit) { return commit.title; },
*/
}

};
9 changes: 9 additions & 0 deletions config/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable node/no-unsupported-features, no-console */
'use strict';
/* eslint-disable node/no-unpublished-require */
const generateChangelog = require('ember-cli-changelog/lib/tasks/release-with-changelog');

module.exports = {
publish: true,
beforeCommit: generateChangelog
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"postpublish": "ember ts:clean"
},
"dependencies": {
"ember-decorators": "5.1.4",
"@ember-decorators/babel-transforms": "^2.1.2",
"ember-cli-babel": "7.6.0",
"ember-cli-typescript": "^2.0.0",
"ember-cli-moment-shim": "^3.7.1",
"ember-cli-typescript": "^2.0.0",
"ember-decorators": "5.1.4",
"moment": "^2.24.0"
},
"devDependencies": {
"@ember/optional-features": "^0.6.3",
"@ember/jquery": "^0.6.0",
"@ember/optional-features": "^0.6.3",
"@types/ember": "^3.1.0",
"@types/ember-data": "^3.1.7",
"@types/ember-qunit": "^3.4.6",
Expand All @@ -44,11 +44,13 @@
"broccoli-asset-rev": "^2.7.0",
"ember-awesome-macros": "^4.0.0",
"ember-cli": "~3.8.1",
"ember-cli-changelog": "^0.3.4",
"ember-cli-dependency-checker": "^3.1.0",
"ember-cli-eslint": "^4.2.3",
"ember-cli-htmlbars": "^3.0.0",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
"ember-cli-inject-live-reload": "^1.8.2",
"ember-cli-release": "^1.0.0-beta.2",
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-typescript-blueprints": "^2.0.0",
Expand Down

0 comments on commit 245a5c1

Please sign in to comment.