Skip to content

Commit

Permalink
Add filepicker for artist image uploads
Browse files Browse the repository at this point in the history
There is still some UI cleanup to be done, and adding title and description for images
  • Loading branch information
Ian VanSchooten authored and jamemackson committed Jul 16, 2015
1 parent 38dcaa1 commit b5dc403
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 67 deletions.
30 changes: 30 additions & 0 deletions client/app/pods/admin/artist/images/new/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Ember from 'ember';

export default Ember.ObjectController.extend({

showFilePicker: false,

actions : {
showPicker: function() {
this.set('showFilePicker', true);
},
hidePicker: function() {
this.set('showFilePicker', false);
},
fileSelected: function(data) {
var self = this;
data.forEach(function (upload){
let image = self.store.createRecord('image', { artist: self.get('model')});
image.set('path', upload.url);
});
this.send('hidePicker');
},
onClose: function() {
this.send('hidePicker');
},
onError: function(error) {
this.send('hidePicker');
}
}

});
107 changes: 54 additions & 53 deletions client/app/pods/admin/artist/images/new/route.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.createRecord('image', { artist: this.modelFor('admin.artist')});

renderTemplate() {
this.render({ outlet: 'newImage', into: 'admin/artist'});
},
actions: {
queueImage(file) {
let controller = this.controller;
let image = controller.get('model');
image.set('file', file);
file.read().then(function setPreviewUrl(url) {
if (image.get('url') == null) {
image.set('url', url);
}
});
},
saveArtistImage() {
let controller = this.controller;
let image = controller.get('model');
let artist = this.modelFor('admin.artist');
if (image && artist) {
let accessToken = this.container.lookup('simple-auth-authorizer:oauth2-bearer').session.content.access_token;
let file = image.file;
let host = this.store.adapterFor('application').get('host');
let namespace = this.store.adapterFor('application').get('namespace');
let url = host + '/' + namespace + '/uploads/image';
// queueImage(file) {
// let controller = this.controller;
// let image = controller.get('model');
// image.set('file', file);
// file.read().then(function setPreviewUrl(url) {
// if (image.get('url') == null) {
// image.set('url', url);
// }
// });
// },
// saveArtistImage() {
// let controller = this.controller;
// let image = controller.get('model');
// let artist = this.modelFor('admin.artist');
// if (image && artist) {
// let accessToken = this.container.lookup('simple-auth-authorizer:oauth2-bearer').session.content.access_token;
// let file = image.file;
// let host = this.store.adapterFor('application').get('host');
// let namespace = this.store.adapterFor('application').get('namespace');
// let url = host + '/' + namespace + '/uploads/image';

file.upload(url, {
data: {
path: '/images/artists/' + artist.get('slug')
// artist: artist.get('slug'),
// title: image.get('title'),
// description: image.get('description'),
// order: image.get('order')
},
headers: { Authorization: 'bearer ' + accessToken }
}).then(function uploadSucceeded(response) {
// console.log(response);
image.set('path', response.body.path);
image.save();
}).then(
this.transitionTo('admin.artist')
).catch(function uploadFailed(error) {
console.error(error);
image.rollback();
console.error('Could not upload image.');
});
return false;
}
},
cancelNewArtistImage() {
let controller = this.controller;
let image = controller.get('model');
if (image) {
image.rollback();
}
this.transitionTo('admin.artist');
}
// file.upload(url, {
// data: {
// path: '/images/artists/' + artist.get('slug')
// // artist: artist.get('slug'),
// // title: image.get('title'),
// // description: image.get('description'),
// // order: image.get('order')
// },
// headers: { Authorization: 'bearer ' + accessToken }
// }).then(function uploadSucceeded(response) {
// // console.log(response);
// image.set('path', response.body.path);
// image.save();
// }).then(
// this.transitionTo('admin.artist')
// ).catch(function uploadFailed(error) {
// console.error(error);
// image.rollback();
// console.error('Could not upload image.');
// });
// return false;
// }
// },
// cancelNewArtistImage() {
// let controller = this.controller;
// let image = controller.get('model');
// if (image) {
// image.rollback();
// }
// this.transitionTo('admin.artist');
// }
}
});
6 changes: 5 additions & 1 deletion client/app/pods/admin/artist/images/new/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<div class="ui basic segment two fields">
{{#unless controller.model.url}}
<div class="two wide field">
{{image-upload-button action='queueImage'}}
{{!-- {{image-upload-button action='queueImage'}} --}}
{{#if showFilePicker}}
{{ember-filepicker pickerOptions=pickerOptions multiple=true onSelection='fileSelected' onClose='onClose' onError='onError'}}
{{/if}}
<button {{action 'showPicker'}}>Choose Images</button>
</div>
{{/unless}}
<div class="four wide field">
Expand Down
5 changes: 0 additions & 5 deletions client/app/pods/admin/artist/index/route.js

This file was deleted.

1 change: 0 additions & 1 deletion client/app/pods/admin/artist/index/template.hbs

This file was deleted.

2 changes: 1 addition & 1 deletion client/app/pods/admin/artist/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
artist art
</div>
<div class="content">

<div class="ui dividing header">artist images</div>
{{outlet "newImage"}}
{{partial "admin/artist/view-images-form"}}
</div>
{{!-- start of exhibitions tab --}}
Expand Down
8 changes: 5 additions & 3 deletions client/app/pods/admin/artist/view-images-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<div class="caption">
{{#link-to 'admin.artist.images.new' class="ui small button"}}New Artist Image{{/link-to}}
</div>
<div class="ui four cards">
{{#if model.images}}
<div class="ui four cards">
{{#each model.images as |image|}}
<div class="ui card">
{{image-preview src=image.fullUrl title=image.title alt=image.description}}
{{image-preview src=image.path title=image.title alt=image.description}}
<div class="content">
<div class="header">{{image.title}}</div>
<div class="description">
Expand All @@ -19,5 +20,6 @@
</div>
</div>
{{/each}}
</div>
</div>
{{/if}}
</div>
4 changes: 2 additions & 2 deletions client/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var Router = Ember.Router.extend({
});

export default Router.map(function () {
this.route('index', { path: '/'}, function () {});
// this.route('index', { path: '/'}, function () {});

this.route('login');
this.route('register');

this.route('event', function () {});
this.route('user', function () {});
this.route('artists', function () {
this.route('new');
// this.route('new');
});
this.resource('artist', { path: '/artist/:artist_slug' }, function () {
// this.route('index', { path: '/artist/:artist_slug' });
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-document-title": "0.0.3",
"ember-cli-filepicker": "0.1.2",
"ember-cli-filepicker": "0.1.95",
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
Expand Down

0 comments on commit b5dc403

Please sign in to comment.