1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

Enabled write operation for member name and note

no issue

- Allows editing member's name and note in admin
This commit is contained in:
Rish 2019-10-10 17:29:35 +05:30
parent d1fe33f073
commit f0c906f289
7 changed files with 49 additions and 21 deletions

View file

@ -10,7 +10,6 @@ export default Component.extend({
mediaQueries: service(),
isViewingSubview: false,
scratchDescription: '',
// Allowed actions
setProperty: () => {},
@ -18,6 +17,7 @@ export default Component.extend({
scratchName: boundOneWay('member.name'),
scratchEmail: boundOneWay('member.email'),
scratchNote: boundOneWay('member.note'),
subscriptions: computed('member.stripe', function () {
let subscriptions = this.member.get('stripe');
if (subscriptions && subscriptions.length > 0) {

View file

@ -12,8 +12,9 @@ export default Controller.extend({
router: service(),
member: alias('model'),
notifications: service(),
member: alias('model'),
subscribedAt: computed('member.createdAt', function () {
let memberSince = moment(this.member.createdAt).from(moment());
let createdDate = moment(this.member.createdAt).format('MMM DD, YYYY');
@ -21,8 +22,8 @@ export default Controller.extend({
}),
actions: {
setProperty() {
return;
setProperty(propKey, value) {
this._saveMemberProperty(propKey, value);
},
toggleDeleteTagModal() {
this.toggleProperty('showDeleteMemberModal');
@ -37,6 +38,22 @@ export default Controller.extend({
}
},
save: task(function* () {
let member = this.member;
try {
return yield member.save();
} catch (error) {
if (error) {
this.notifications.showAPIError(error, {key: 'member.save'});
}
}
}).drop(),
_saveMemberProperty(propKey, newValue) {
let member = this.member;
member.set(propKey, newValue);
},
fetchMember: task(function* (memberId) {
this.set('isLoading', true);
yield this.store.findRecord('member', memberId, {

View file

@ -4,6 +4,7 @@ import attr from 'ember-data/attr';
export default DS.Model.extend({
name: attr('string'),
email: attr('string'),
note: attr('string'),
createdAt: attr('moment-utc'),
stripe: attr('member-subscription')
});

15
app/serializers/member.js Normal file
View file

@ -0,0 +1,15 @@
/* eslint-disable camelcase */
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
serialize(/*snapshot, options*/) {
let json = this._super(...arguments);
// Properties that exist on the model but we don't want sent in the payload
delete json.stripe;
// Normalize properties
json.name = json.name || '';
json.note = json.note || '';
return json;
}
});

View file

@ -4,7 +4,6 @@
{{#gh-form-group errors=member.errors hasValidated=member.hasValidated property="name"}}
<label for="member-name">Name</label>
{{gh-text-input
disabled=true
id="member-name"
name="name"
value=(readonly scratchName)
@ -29,19 +28,18 @@
</div>
<div class="mb6 mb0-ns w-100 w-50-ns">
{{#gh-form-group errors=member.errors hasValidated=member.hasValidated property="note"}}
<label for="member-description">Note</label>
<label for="member-note">Note</label>
{{gh-textarea
disabled=true
id="member-description"
name="description"
id="member-note"
name="note"
class="gh-member-details-textarea"
tabindex="3"
value=(readonly scratchDescription)
input=(action (mut scratchDescription) value="target.value")
focus-out=(action 'setProperty' 'description' scratchDescription)
value=(readonly scratchNote)
input=(action (mut scratchNote) value="target.value")
focus-out=(action 'setProperty' 'note' scratchNote)
}}
{{gh-error-message errors=member.errors property="description"}}
<p>Maximum: <b>500</b> characters. Youve used {{gh-count-down-characters scratchDescription 500}}</p>
{{gh-error-message errors=member.errors property="note"}}
<p>Maximum: <b>500</b> characters. Youve used {{gh-count-down-characters scratchNote 500}}</p>
{{/gh-form-group}}
</div>
</div>

View file

@ -10,6 +10,9 @@
{{member.email}}
{{/if}}
</h2>
<section class="view-actions">
{{gh-task-button task=save class="gh-btn gh-btn-blue gh-btn-icon" data-test-button="save"}}
</section>
</GhCanvasHeader>
<div class="flex items-center mb10 bt b--lightgrey-d1 pt8">
<GhMemberAvatar @member={{member}} @sizeClass={{'f-headline fw4 lh-zero'}} class="w18 h18 mr4" />

View file

@ -18,13 +18,7 @@ export default Transform.extend({
if (isEmberArray(deserialized)) {
subscriptionArray = deserialized.map((item) => {
let adapter = item.get('adapter').trim();
let amount = item.get('amount');
let plan = item.get('plan').trim();
let status = item.get('status').trim();
let validUntil = item.get('validUntil');
return {adapter, amount, plan, status, validUntil};
return item;
}).compact();
} else {
subscriptionArray = [];