Last active
May 5, 2021 20:32
-
-
Save onechiporenko/99e1630b806bd4bd6edb5682429079a8 to your computer and use it in GitHub Desktop.
Inline edit and columns summary (v2.3.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
import Ember from 'ember'; | |
export default DS.RESTAdapter.extend({ | |
host: 'https://api.github.com', | |
namespace: 'repos/emberjs/ember.js/issues/13071/comments', | |
token: '', | |
username: '', | |
query(store, b, query) { | |
const url = `${this.get('host')}/${this.get('namespace')}`; | |
const token = this.get('token'); | |
const username = this.get('username'); | |
return this.ajax(url, 'GET', { | |
beforeSend (xhr) { | |
if (username && token) { | |
xhr.setRequestHeader("Authorization", "Basic " + btoa(`${username}:${token}`)); | |
} | |
}, | |
data: query | |
}); | |
}, | |
updateRecord() { | |
return Ember.RSVP.Promise.resolve({meta: {}}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
export default DS.RESTAdapter.extend({ | |
host: 'https://api.github.com', | |
namespace: 'repos/emberjs/ember.js/issues', | |
token: '', | |
username: '', | |
query(store, b, query) { | |
const url = `${this.get('host')}/${this.get('namespace')}`; | |
const token = this.get('token'); | |
const username = this.get('username'); | |
return this.ajax(url, 'GET', { | |
beforeSend (xhr) { | |
if (username && token) { | |
xhr.setRequestHeader("Authorization", "Basic " + btoa(`${username}:${token}`)); | |
} | |
}, | |
data: query | |
}); | |
}, | |
updateRecord() { | |
return Ember.RSVP.Promise.resolve({meta: {}}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
actions: { | |
updateCommentsCount(newVal) { | |
this.set('record.comments', Number(newVal)); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CellColumnSummary from './models-table/cell-column-summary'; | |
export default CellColumnSummary.extend({ | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import layout from '../templates/components/select-toggle'; | |
export default Ember.Component.extend({ | |
layout, | |
actions: { | |
clickOnRow(index, record, event) { | |
this.get('clickOnRow')(index, record); | |
event.stopPropagation(); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
init() { | |
this._super(...arguments); | |
this.set('options', ['open', 'closed']); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
function group(collection) { | |
return Ember.computed(`${collection}.[]`, function() { | |
const c = this.get(collection); | |
return c ? c.reduce((result, item) => { | |
if (!result[item]) { | |
result[item] = 0; | |
} | |
result[item]++; | |
return result; | |
}, {}) : {}; | |
}); | |
} | |
export default Ember.Component.extend({ | |
tagName: 'td', | |
selectedGrouped: group('mappedSelectedItems'), | |
dataGrouped: group('mappedData') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const {set} = Ember; | |
export default Ember.Component.extend({ | |
options: Ember.computed('users.[]', function () { | |
const users = this.get('users'); | |
return users ? users.map(u => { | |
return {label: u.get('login'), value: u.get()}; | |
}) : []; | |
}), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Inline edit and columns summary', | |
token: Ember.computed.alias('commentsAdapter.token'), | |
username: Ember.computed.alias('commentsAdapter.username') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Theme from '../themes/bootstrap3'; | |
export default Ember.Controller.extend({ | |
allUsers: Ember.computed.mapBy('model', 'user'), | |
users: Ember.computed.uniqBy('allUsers', 'id'), | |
columns: [ | |
{ | |
component: 'select-toggle', | |
useFilter: false, | |
editable: false, | |
mayBeHidden: false | |
}, | |
{propertyName: 'type', editable: false, componentForFooterCell: 'type-summary'}, | |
{propertyName: 'user.login', title: 'Author', componentForEdit: 'user-edit'}, | |
{propertyName: 'state', componentForEdit: 'state-edit'}, | |
{propertyName: 'comments', componentForFooterCell: 'comments-summary', componentForEdit: 'comments-edit'}, | |
{propertyName: 'created_at', editable: false, disableFiltering: true}, | |
{propertyName: 'updated_at', editable: false, disableFiltering: true}, | |
{ | |
"title": "Edit", | |
"component": "edit-row", | |
"editable": false | |
} | |
], | |
actions: { | |
onSaveRow(param) { | |
return param.record.save(); | |
}, | |
onCancelRow( { record } ) { | |
record.rollback(); | |
return true; | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function initialize(application) { | |
application.inject('controller:application', 'commentsAdapter', 'adapter:comment'); | |
}; | |
export default { | |
initialize, | |
after: 'ember-data' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
number: attr('number'), | |
title: attr('string'), | |
state: attr('string'), | |
comments: attr('number'), | |
user: belongsTo('user'), | |
type: attr('string'), | |
labels: hasMany('label'), | |
locked: attr('boolean'), | |
assignee: belongsTo('user'), | |
assignees: hasMany('user'), | |
created_at: attr('date'), | |
updated_at: attr('date'), | |
closed_at: attr('date'), | |
author_association: attr('string'), | |
body: attr('string'), | |
html_url: attr('string'), | |
init() { | |
this._super(...arguments); | |
this.startTrack(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
url: attr('string'), | |
name: attr('string'), | |
color: attr('string'), | |
default: attr('boolean') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
login: attr('string'), | |
avatar_url: attr('string'), | |
url: attr('string'), | |
html_url: attr('string'), | |
type: attr('string'), | |
site_admin: attr('boolean') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.get('store').query('issue', {per_page: 100}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.JSONAPISerializer.extend({ | |
pageSize: 10, | |
_mapIncluded(data, type) { | |
const clb = item => ({id: item.id, type, attributes: item}); | |
return Ember.isArray(data) ? data.map(clb) : clb(data); | |
}, | |
normalizeQueryResponse(a, b, payload) { | |
const included = []; | |
const newPayload = { | |
data: payload.map(item => { | |
const itemData = { | |
id: item.id, | |
type: 'issue', | |
attributes: item, | |
relationships: { | |
labels: { | |
data: item.labels.map(label => ({type: 'label', id: label.id})) | |
}, | |
user: { | |
data: { id: item.user.id, type: 'user' } | |
} | |
} | |
}; | |
included.pushObjects(this._mapIncluded(item.labels, 'label')); | |
included.pushObject(this._mapIncluded(item.user, 'user')); | |
itemData.attributes.type = item.pull_request ? 'Pull Request' : 'Issue'; | |
return itemData; | |
}) | |
}; | |
newPayload.included = included; | |
console.log(newPayload); | |
return newPayload; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0", | |
"bs3css": "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css", | |
"bs3js": "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-models-table": "2.3.0", | |
"ember-cli-showdown": "4.1.0", | |
"ember-power-select": "2.0.0-beta.0", | |
"ember-data-change-tracker": "0.7.2", | |
"ember-one-way-controls": "3.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment