diff --git a/README.md b/README.md index cc9d5f0..9379d21 100644 --- a/README.md +++ b/README.md @@ -46,19 +46,22 @@ This example will generate the following HTML inside the app: ``` ### Available Placeholders + +#### Ticket sidebar + * {{ticket.id}} //not available for new tickets * {{ticket.description}} * {{ticket.requester.id}} * {{ticket.requester.name}} * {{ticket.requester.email}} -* {{ticket.requester.externalId}} +* {{ticket.requester.external_id}} * {{ticket.requester.firstname}} * {{ticket.requester.lastname}} * {{ticket.requester.user_fields.YYY}} = custom user fields can be used * {{ticket.assignee.user.id}} * {{ticket.assignee.user.name}} * {{ticket.assignee.user.email}} -* {{ticket.assignee.user.externalId}} +* {{ticket.assignee.user.external_id}} * {{ticket.assignee.user.firstname}} * {{ticket.assignee.user.lastname}} * {{ticket.assignee.group.id}} @@ -68,10 +71,30 @@ This example will generate the following HTML inside the app: * {{current_user.id}} * {{current_user.name}} * {{current_user.email}} -* {{current_user.externalId}} +* {{current_user.external_id}} * {{current_user.firstname}} * {{current_user.lastname}} +#### User sidebar + +* {{user.id}} +* {{user.name}} +* {{user.email}} +* {{user.phone}} +* {{user.external_id}} +* {{user.firstname}} +* {{user.lastname}} +* {{user.user_fields.YYY}} = custom user fields can be used +* {{user.organization.id}} (if user belongs to multiple organizations, only the default one will be used) +* {{user.organization.name}} +* {{user.organization.external_id}} +* {{user.organization.organization_fields.XXXXXXX}} = custom organization fields can be used + + +### Screenshots + +![](/assets/screenshot.png) + ### Making changes If you wish to change the output, locate the app by looking for the name you choose in step 4 above. Use the widget to `Change Settings` diff --git a/app.js b/app.js index a15df64..871851c 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,7 @@ requests: { fetchUsers: function(ids) { return { - url: helpers.fmt('/api/v2/users/show_many.json?ids=%@&include=organizations,groups', ids.join(',')), + url: helpers.fmt('/api/v2/users/show_many.json?ids=%@&include=organizations', ids.join(',')), type: 'GET', dataType: 'json' }; @@ -11,28 +11,47 @@ }, events: { - 'app.created' : 'onAppCreated', - '*.changed' : function(e) { + 'app.created': 'onAppCreated', + '*.changed' : function(e) { if (_.contains(this.fieldsToWatch(), e.propertyName)) return this.onAppActivated(); - }, - 'fetchUsers.done' : 'onFetchUsersDone' + } }, onAppCreated: function() { + switch (this.currentLocation()) { + case "user_sidebar": + this.prepareTemplateForUser(); + break; + case "ticket_sidebar": + this.prepareTemplateForTicket(); + break; + } + }, + + prepareTemplateForUser: function() { + this.ajax('fetchUsers', [this.user().id()]).done(function(data) { + var context = this.getUserContext(data); + this.prepareTemplate(context); + }); + }, + + prepareTemplateForTicket: function() { var userIds = _.compact(_.uniq([ (this.ticket().assignee().user() && this.ticket().assignee().user().id()), this.currentUser().id(), (this.ticket().requester() && this.ticket().requester().id()) ])); - this.ajax('fetchUsers', userIds); + this.ajax('fetchUsers', userIds).done(function(data) { + var context = this.getTicketContext(data); + this.prepareTemplate(context); + }); }, - onFetchUsersDone: function(data) { + prepareTemplate: function(context) { var templateUris = this.getUriTemplatesFromSettings(), templateOptions = { interpolate : /\{\{(.+?)\}\}/g }, - context = this.getContext(data), uris = _.map(templateUris, function(uri){ try { uri.url = _.template(uri.url, templateOptions)(context); @@ -50,7 +69,20 @@ return JSON.parse(this.settings.uri_templates); }, - getContext: function(data){ + getUserContext: function(data) { + var context = _.clone(this.containerContext()); + context.user = this.decorateUser(data.users[0]); + + if (context.user.organization_id) { + context.user.organization = _.find(data.organizations, function(org) { + return org.id == context.user.organization_id; + }); + } + + return context; + }, + + getTicketContext: function(data) { var context = _.clone(this.containerContext()); if (context.ticket.requester.id) { @@ -82,7 +114,7 @@ }, this); }, - decorateUser: function(user){ + decorateUser: function(user) { var name = (user.name || '').split(' '); user.firstname = name[0] || ''; @@ -91,7 +123,7 @@ return user; }, - fieldsToWatch: _.memoize(function(){ + fieldsToWatch: _.memoize(function() { return _.reduce(this.getUriTemplatesFromSettings(), function(memo, uri){ var fields = _.map(uri.url.match(/\{\{(.+?)\}\}/g), function(f){ return f.slice(2,-2); }); diff --git a/assets/logo-small.png b/assets/logo-small.png index 7f1cfd3..6ad2d03 100644 Binary files a/assets/logo-small.png and b/assets/logo-small.png differ diff --git a/assets/logo.png b/assets/logo.png index 7f1cfd3..1bc5176 100644 Binary files a/assets/logo.png and b/assets/logo.png differ diff --git a/assets/screenshot.png b/assets/screenshot.png new file mode 100644 index 0000000..a5d0929 Binary files /dev/null and b/assets/screenshot.png differ diff --git a/manifest.json b/manifest.json index 9a57b30..35b69ac 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "name": "Url Builder App", + "name": "URL Builder App", "author": { "name": "Zendesk Services", "email": "services@zendesk.com" @@ -7,8 +7,9 @@ "defaultLocale": "en", "private": true, - "location": ["ticket_sidebar", "new_ticket_sidebar"], - "frameworkVersion": "0.5", + "location": ["ticket_sidebar", "new_ticket_sidebar", "user_sidebar"], + "frameworkVersion": "1.0", + "version": "1.1", "parameters": [ { diff --git a/translations/en.json b/translations/en.json index 94c622b..cd9918d 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1,11 +1,11 @@ { "app": { - "description": "Simple url generator", - "name": "Simple Url", + "description": "Simple URL generator", + "name": "Simple URL generator", "parameters": { "uri_templates": { - "label": "A JSON Array of urls.", + "label": "A JSON Array of URLs.", "helpText": "See https://github.com/zendesklabs/url_builder_app/blob/master/README.md for more information." } }