mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-10 08:26:39 +00:00
DSS-5869 Adds Component: dataset-favorite
This commit is contained in:
parent
8e6f8d1a31
commit
cc11347e5a
27
wherehows-web/app/components/dataset-favorite.js
Normal file
27
wherehows-web/app/components/dataset-favorite.js
Normal file
@ -0,0 +1,27 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
actions: {
|
||||
favorites: function(dataset) {
|
||||
var url = '/api/v1/datasets/' + dataset.id + '/favorite'
|
||||
var method = !dataset.isFavorite ? 'POST' : 'DELETE'
|
||||
var token = $("#csrfToken").val().replace('/', '')
|
||||
var _this = this
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: method,
|
||||
headers: {
|
||||
'Csrf-Token': token
|
||||
},
|
||||
dataType: 'json',
|
||||
data: {
|
||||
csrfToken: token
|
||||
}
|
||||
}).done(function(data, txt, xhr){
|
||||
_this.set('dataset.isFavorite', !dataset.isFavorite)
|
||||
}).fail(function(xhr, txt, err){
|
||||
console.log('Error: Could not update dataset favorite.')
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
<i class="wh-clickable-icon fa {{if dataset.isFavorite 'fa-heart'}} {{unless dataset.isFavorite 'fa-heart-o'}}"
|
||||
{{action "favorites" dataset}}>
|
||||
{{yield}}
|
||||
</i>
|
Loading…
x
Reference in New Issue
Block a user