voluntary_ranking 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/voluntary_ranking/app.js +2 -4
- data/app/assets/javascripts/voluntary_ranking/{views/arguments/new_view.js.coffee → components/new_argument_component.js.coffee} +2 -2
- data/app/assets/javascripts/voluntary_ranking/{views/ranking_items/colllection_view.js.coffee → components/ranking_items_collection_component.js.coffee} +4 -6
- data/app/assets/javascripts/voluntary_ranking/controllers/arguments/new_controller.js.coffee +9 -2
- data/app/assets/javascripts/voluntary_ranking/controllers/thing_controller.js.coffee +29 -0
- data/app/assets/javascripts/voluntary_ranking/helpers/stars_html_helper.js.coffee +4 -2
- data/app/assets/javascripts/voluntary_ranking/mixins/pagination_controller.js.coffee +6 -1
- data/app/assets/javascripts/voluntary_ranking/models/ranking_item.js.coffee +1 -1
- data/app/assets/javascripts/voluntary_ranking/router.js.coffee +3 -4
- data/app/assets/javascripts/voluntary_ranking/routes/arguments/index_route.js.coffee +6 -2
- data/app/assets/javascripts/voluntary_ranking/routes/compare_things/arguments_route.js.coffee +1 -1
- data/app/assets/javascripts/voluntary_ranking/routes/profile/rankings_route.js.coffee +3 -1
- data/app/assets/javascripts/voluntary_ranking/routes/rankings/index_route.js.coffee +3 -1
- data/app/assets/javascripts/voluntary_ranking/routes/rankings/show_route.js.coffee +3 -1
- data/app/assets/javascripts/voluntary_ranking/routes/thing_route.js.coffee +13 -1
- data/app/assets/javascripts/voluntary_ranking/routes/things_comparison_matrix_route.js.coffee +11 -0
- data/app/assets/javascripts/voluntary_ranking/templates/arguments/new.js.handlebars +2 -1
- data/app/assets/javascripts/voluntary_ranking/templates/ranking_items/_collection.js.handlebars +7 -7
- data/app/assets/javascripts/voluntary_ranking/templates/shared/_pagination.js.handlebars +8 -8
- data/app/assets/javascripts/voluntary_ranking/templates/thing.js.handlebars +10 -2
- data/app/assets/javascripts/voluntary_ranking/templates/things_comparison_matrix.js.handlebars +22 -0
- data/app/assets/javascripts/voluntary_ranking/templates/user/rankings/details.js.handlebars +5 -1
- data/app/controllers/api/v1/rankings_controller.rb +1 -1
- data/app/controllers/api/v1/things_controller.rb +1 -1
- data/app/models/ranking.rb +1 -1
- data/app/models/user_ranking_item.rb +5 -1
- data/config/routes.rb +0 -12
- data/lib/voluntary_ranking/version.rb +1 -1
- metadata +27 -29
- data/app/assets/javascripts/voluntary_ranking/base.js.coffee +0 -3
- data/app/assets/javascripts/voluntary_ranking/components/modal_dialog_component.js.coffee +0 -6
- data/app/assets/javascripts/voluntary_ranking/helpers/name_with_apostrophe_helper.js.coffee +0 -5
- data/app/assets/javascripts/voluntary_ranking/mixins/has_current_user.js.coffee +0 -4
- data/app/assets/javascripts/voluntary_ranking/mixins/singleton.js.coffee +0 -17
- data/app/assets/javascripts/voluntary_ranking/models/argument.js.coffee +0 -7
- data/app/assets/javascripts/voluntary_ranking/templates/components/modal-dialog.js.handlebars +0 -9
- data/app/assets/javascripts/voluntary_ranking/views/application/index_view.js.coffee +0 -1
- data/app/assets/javascripts/voluntary_ranking/views/index_view.js.coffee +0 -1
- data/app/assets/javascripts/voluntary_ranking/views/shared/pagination.js +0 -4
- data/app/controllers/api/v1/argument_topics_controller.rb +0 -12
- data/app/controllers/api/v1/arguments_controller.rb +0 -32
- data/app/controllers/api/v1/things/arguments_controller.rb +0 -40
- data/app/models/argument.rb +0 -48
- data/app/models/argument_topic.rb +0 -7
- data/app/serializers/argument_serializer.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76f45df67cb3f035e730281227f3862b7de1088a
|
|
4
|
+
data.tar.gz: 119fa32bedaa5329a994e8b2402161c74e4cfd02
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4345d300c059616625ad2c63065511e8776ea2f17e36a7e75b0eb2b452e49a2de2ecf2a0322639a8370f43631220cac3ae84304412728afc61275531b6965aeb
|
|
7
|
+
data.tar.gz: 31301321664b6edb916d5c452ac8ab721888f8858474069847eb1f6716fa726593a0f7b5244a0d7d7ec02b3ab8d55293adfc1a007b253c820a47719a00c5551b
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
//= require_tree ./components
|
|
1
2
|
//= require_tree ./mixins
|
|
2
3
|
//= require_tree ./models
|
|
3
4
|
//= require_tree ./controllers
|
|
4
|
-
//= require_tree ./components
|
|
5
|
-
//= require_tree ./views
|
|
6
5
|
//= require_tree ./helpers
|
|
7
6
|
//= require_tree ./templates
|
|
8
7
|
//= require ./router.js.coffee
|
|
9
8
|
//= require_tree ./routes
|
|
10
|
-
//= require_self
|
|
11
|
-
//= require ./base.js.coffee
|
|
9
|
+
//= require_self
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Volontariat.
|
|
1
|
+
Volontariat.NewArgumentComponent = Ember.Component.extend
|
|
2
2
|
didInsertElement: ->
|
|
3
3
|
$('input[data-append-autocomplete]').each (k, v) ->
|
|
4
4
|
$(v).autocomplete
|
|
@@ -6,4 +6,4 @@ Volontariat.ArgumentsNewView = Ember.View.extend
|
|
|
6
6
|
appendTo: '#topic_suggestions'
|
|
7
7
|
select: (event, ui) ->
|
|
8
8
|
$(this).val(ui.item.value)
|
|
9
|
-
false
|
|
9
|
+
false
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
Volontariat.
|
|
2
|
-
templateName: 'ranking_items/_collection'
|
|
3
|
-
|
|
1
|
+
Volontariat.RankingItemsCollectionComponent = Ember.Component.extend
|
|
4
2
|
didInsertElement: ->
|
|
5
3
|
first_position = $('#ranking li:first').data('position')
|
|
6
4
|
last_position = $('#ranking li:last').data('position')
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
|
|
6
|
+
$( '#ranking' ).sortable
|
|
9
7
|
handle: '.ranking_item_sortable'
|
|
10
8
|
start: (event, ui) =>
|
|
11
9
|
first_position = $('#ranking li:first').data('position')
|
|
@@ -22,4 +20,4 @@ Volontariat.RankingItemsCollectionView = Ember.View.extend
|
|
|
22
20
|
if $(element).data('id') == $(source_item).data('id')
|
|
23
21
|
$.post '/api/v1/user_ranking_items/' + $(element).data('id') + '/move', { _method: 'put', position: Volontariat.current_position }
|
|
24
22
|
|
|
25
|
-
Volontariat.current_position += 1
|
|
23
|
+
Volontariat.current_position += 1
|
data/app/assets/javascripts/voluntary_ranking/controllers/arguments/new_controller.js.coffee
CHANGED
|
@@ -5,9 +5,16 @@ Volontariat.ArgumentsNewController = Ember.Controller.extend
|
|
|
5
5
|
|
|
6
6
|
create: ->
|
|
7
7
|
# TODO: replace manual ajax logic by createRecord usage if the thingId can be passed
|
|
8
|
-
#argument = @store.createRecord('argument', topicName: @get('topicName'),
|
|
8
|
+
#argument = @store.createRecord('argument', topicName: @get('topicName'), argumentableType: 'Thing', argumentableId: $('#thing_id').val(), value: @get('value'))
|
|
9
9
|
#argument.save()
|
|
10
|
-
$.post(
|
|
10
|
+
$.post(
|
|
11
|
+
'/api/v1/arguments', {
|
|
12
|
+
argument: {
|
|
13
|
+
topic_name: @get('topicName'), argumentable_type: 'Thing', argumentable_name: $('#thing_name').val(),
|
|
14
|
+
value: @get('value')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
).success =>
|
|
11
18
|
@send "closeModal"
|
|
12
19
|
@transitionToRoute('no_data')
|
|
13
20
|
@transitionToRoute('arguments.index', $('#thing_name').val(), 1)
|
|
@@ -6,5 +6,34 @@ Volontariat.ThingController = Ember.Controller.extend
|
|
|
6
6
|
compare: ->
|
|
7
7
|
@transitionToRoute('compare_things', @get('name'), @get('otherThingName'))
|
|
8
8
|
|
|
9
|
+
addToComparisonList: ->
|
|
10
|
+
list = []
|
|
11
|
+
|
|
12
|
+
unless Cookies.get('thingComparisonList') == undefined
|
|
13
|
+
list = Cookies.getJSON 'thingComparisonList'
|
|
14
|
+
|
|
15
|
+
if list.length == 4
|
|
16
|
+
alert Volontariat.t('things.show.limit_of_comparison_list')
|
|
17
|
+
|
|
18
|
+
return false
|
|
19
|
+
|
|
20
|
+
list.push @get('thingId')
|
|
21
|
+
|
|
22
|
+
Cookies.set 'thingComparisonList', list, expires: 7
|
|
23
|
+
@controllerFor('thing').set 'thingComparisonListCount', list.length
|
|
24
|
+
@set 'onComparisonList', true
|
|
25
|
+
|
|
26
|
+
removeFromComparisonList: ->
|
|
27
|
+
list = jQuery.grep(Cookies.getJSON('thingComparisonList'), (id) =>
|
|
28
|
+
id != @get('thingId')
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
Cookies.set 'thingComparisonList', list, expires: 7
|
|
32
|
+
@controllerFor('thing').set 'thingComparisonListCount', list.length
|
|
33
|
+
@set 'onComparisonList', false
|
|
34
|
+
|
|
35
|
+
goToComparisonList: ->
|
|
36
|
+
@transitionToRoute 'things_comparison_matrix'
|
|
37
|
+
|
|
9
38
|
close: ->
|
|
10
39
|
@send "closeModal"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
Ember.
|
|
1
|
+
Volontariat.StarsHtmlHelper = Ember.Helper.helper((params) ->
|
|
2
|
+
value = params[0]
|
|
2
3
|
text = ''
|
|
3
4
|
|
|
4
5
|
if value == 5
|
|
@@ -26,4 +27,5 @@ Ember.Handlebars.helper 'stars-html', (value, options) ->
|
|
|
26
27
|
else
|
|
27
28
|
text += '<span></span>'
|
|
28
29
|
|
|
29
|
-
new (Ember.Handlebars.SafeString)(text)
|
|
30
|
+
new (Ember.Handlebars.SafeString)(text)
|
|
31
|
+
)
|
|
@@ -11,7 +11,12 @@ Volontariat.PaginationController = Em.Mixin.create
|
|
|
11
11
|
_goToPage: (page) ->
|
|
12
12
|
page = parseInt(page)
|
|
13
13
|
@set('page', page)
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
if @get('metadata')
|
|
16
|
+
@set 'totalPages', @get('metadata').pagination.total_pages
|
|
17
|
+
else
|
|
18
|
+
@set 'totalPages', 1
|
|
19
|
+
|
|
15
20
|
pages = []; i = page - 4
|
|
16
21
|
|
|
17
22
|
while i <= page
|
|
@@ -24,7 +24,6 @@ Volontariat.Router.map ->
|
|
|
24
24
|
@resource 'compare_things', path: '/things/:left_thing_name/vs/:right_thing_name', ->
|
|
25
25
|
@route 'arguments', path: ':side/arguments/page/:page'
|
|
26
26
|
|
|
27
|
-
@
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@route 'no_data'
|
|
27
|
+
@route 'things_comparison_matrix'
|
|
28
|
+
|
|
29
|
+
@resource 'ranking_item', path: '/things/:thing_name/is_one_of_the/:adjective/:topic/:scope/page/:page'
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Volontariat.ArgumentsIndexRoute = Ember.Route.extend
|
|
2
2
|
model: (params) ->
|
|
3
3
|
@controllerFor('arguments.index').set 'page', parseInt(params.page)
|
|
4
|
-
|
|
4
|
+
#@controllerFor('arguments.index').set 'thingName', @modelFor('thing')._internalModel._data.name
|
|
5
|
+
#@controllerFor('arguments.index').set 'thingName', @modelFor('thing').name
|
|
6
|
+
@controllerFor('arguments.index').set 'thingName', window.location.hash.split('/')[2]
|
|
5
7
|
|
|
6
|
-
@store.query
|
|
8
|
+
@store.query('argument', argumentable_type: 'Thing', argumentable_id: @modelFor('thing').id, page: params.page).then (result) =>
|
|
9
|
+
@controllerFor('arguments.index').set 'metadata', result.get('meta')
|
|
10
|
+
result
|
|
7
11
|
|
|
8
12
|
setupController: (controller, model) ->
|
|
9
13
|
controller.send('goToPageWithoutRedirect', controller.get('page'))
|
data/app/assets/javascripts/voluntary_ranking/routes/compare_things/arguments_route.js.coffee
CHANGED
|
@@ -4,7 +4,7 @@ Volontariat.CompareThingsArgumentsRoute = Ember.Route.extend
|
|
|
4
4
|
@controllerFor('compare_things.arguments').set 'rightThingName', @modelFor('compare_things').rightThingName
|
|
5
5
|
@controllerFor('compare_things.arguments').set 'page', parseInt(params.page)
|
|
6
6
|
|
|
7
|
-
Ember.$.getJSON("/api/v1/things/#{@modelFor('compare_things').leftThingName}/vs/#{@modelFor('compare_things').rightThingName}/arguments.json?page=#{params.page}&side=#{params.side}").then (json) =>
|
|
7
|
+
Ember.$.getJSON("/api/v1/things/#{@modelFor('compare_things').leftThingName}/vs/#{@modelFor('compare_things').rightThingName}/arguments.json?argumentable_type=Thing&page=#{params.page}&side=#{params.side}").then (json) =>
|
|
8
8
|
@controllerFor('compare_things.arguments').set('metadata', json.meta)
|
|
9
9
|
json.arguments
|
|
10
10
|
|
|
@@ -17,7 +17,9 @@ Volontariat.ProfileRankingsRoute = Ember.Route.extend
|
|
|
17
17
|
user_id: Volontariat.User.current().id, adjective: params.adjective,
|
|
18
18
|
negative_adjective: params.negative_adjective, topic: params.topic,
|
|
19
19
|
scope: params.scope, page: params.page
|
|
20
|
-
)
|
|
20
|
+
).then (result) =>
|
|
21
|
+
@controllerFor('profile.rankings').set 'metadata', result.get('meta')
|
|
22
|
+
result
|
|
21
23
|
|
|
22
24
|
setupController: (controller, model) ->
|
|
23
25
|
unless Volontariat.User.current() == undefined
|
|
@@ -3,7 +3,9 @@ Volontariat.RankingsIndexRoute = Ember.Route.extend
|
|
|
3
3
|
@controllerFor('rankings.index').set 'page', parseInt(params.page)
|
|
4
4
|
@controllerFor('rankings.index').set 'thingName', @modelFor('thing').get('name')
|
|
5
5
|
|
|
6
|
-
@store.query
|
|
6
|
+
@store.query('ranking', thing_id: @modelFor('thing').id, page: params.page).then (result) =>
|
|
7
|
+
@controllerFor('rankings.index').set 'metadata', result.get('meta')
|
|
8
|
+
result
|
|
7
9
|
|
|
8
10
|
setupController: (controller, model) ->
|
|
9
11
|
controller.send('goToPageWithoutRedirect', controller.get('page'))
|
|
@@ -12,7 +12,9 @@ Volontariat.RankingsShowRoute = Ember.Route.extend
|
|
|
12
12
|
'ranking_item',
|
|
13
13
|
adjective: params.adjective, negative_adjective: params.negative_adjective, topic: params.topic,
|
|
14
14
|
scope: params.scope, page: params.page
|
|
15
|
-
)
|
|
15
|
+
).then (result) =>
|
|
16
|
+
@controllerFor('rankings.show').set 'metadata', result.get('meta')
|
|
17
|
+
result
|
|
16
18
|
|
|
17
19
|
setupController: (controller, model) ->
|
|
18
20
|
controller.send('goToPageWithoutRedirect', controller.get('page'))
|
|
@@ -4,4 +4,16 @@ Volontariat.ThingRoute = Ember.Route.extend
|
|
|
4
4
|
@transitionTo('rankings.index', params.name, 1)
|
|
5
5
|
|
|
6
6
|
@controllerFor('thing').set 'name', params.name
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
thingIds = []
|
|
9
|
+
|
|
10
|
+
if Cookies.get('thingComparisonList') == undefined
|
|
11
|
+
@controllerFor('thing').set 'thingComparisonListCount', 0
|
|
12
|
+
else
|
|
13
|
+
thingIds = Cookies.getJSON('thingComparisonList')
|
|
14
|
+
@controllerFor('thing').set 'thingComparisonListCount', thingIds.length
|
|
15
|
+
|
|
16
|
+
@store.find('thing', params.name).then (thing) =>
|
|
17
|
+
@controllerFor('thing').set 'thingId', thing.id
|
|
18
|
+
@controllerFor('thing').set 'onComparisonList', jQuery.inArray(thing.id, thingIds) > -1
|
|
19
|
+
thing
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Volontariat.ThingsComparisonMatrixRoute = Ember.Route.extend
|
|
2
|
+
model: (params) ->
|
|
3
|
+
if Cookies.get('thingComparisonList') == undefined
|
|
4
|
+
[]
|
|
5
|
+
else
|
|
6
|
+
argumentables = []
|
|
7
|
+
|
|
8
|
+
$.each Cookies.getJSON('thingComparisonList'), (index, value) ->
|
|
9
|
+
argumentables.push { type: 'Thing', id: value }
|
|
10
|
+
|
|
11
|
+
Ember.$.getJSON("/api/v1/arguments/matrix", argumentables: argumentables)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
{{#new-argument}}{{/new-argument}}
|
|
1
2
|
{{#modal-dialog action="close"}}
|
|
2
3
|
<form class="form-inline" id="new_argument_form">
|
|
3
4
|
<div class="modal-header">
|
|
@@ -14,4 +15,4 @@
|
|
|
14
15
|
<button class="save_argument_button" {{action 'create'}}>Submit</button>
|
|
15
16
|
</div>
|
|
16
17
|
</form>
|
|
17
|
-
{{/modal-dialog}}
|
|
18
|
+
{{/modal-dialog}}
|
data/app/assets/javascripts/voluntary_ranking/templates/ranking_items/_collection.js.handlebars
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
<table class="table" style="margin-bottom: 0px">
|
|
3
3
|
<thead>
|
|
4
4
|
<tr>
|
|
5
|
-
{{#if
|
|
5
|
+
{{#if yourRanking}}
|
|
6
6
|
<th width="2%"></th>
|
|
7
7
|
{{/if}}
|
|
8
8
|
<th width="5%" style="vertical-align:top;">Position</th>
|
|
9
|
-
{{#if
|
|
9
|
+
{{#if yourRanking}}
|
|
10
10
|
<th width="5%" style="vertical-align:top; text-align:center;">Move</th>
|
|
11
11
|
<th width="70%" style="vertical-align:top;">Name</th>
|
|
12
12
|
{{else}}
|
|
13
13
|
<th width="80%" style="vertical-align:top;">Name</th>
|
|
14
14
|
{{/if}}
|
|
15
15
|
<th width="15%" style="vertical-align:top; text-align:center;">Stars</th>
|
|
16
|
-
{{#if
|
|
16
|
+
{{#if yourRanking}}
|
|
17
17
|
<th width="5%"></th>
|
|
18
18
|
{{/if}}
|
|
19
19
|
</tr>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<li class="ranking_item_{{unbound rankingItem.id}}" data-id="{{unbound rankingItem.id}}" data-position="{{unbound rankingItem.position}}">
|
|
27
27
|
<table class="table">
|
|
28
28
|
<tr>
|
|
29
|
-
{{#if
|
|
29
|
+
{{#if yourRanking}}
|
|
30
30
|
<td width="2%" style="text-align:center">
|
|
31
31
|
<span class="ranking_item_sortable glyphicon glyphicon-move"></span>
|
|
32
32
|
</td>
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
{{rankingItem.position}}
|
|
37
37
|
{{/link-to}}
|
|
38
38
|
</td>
|
|
39
|
-
{{#if
|
|
39
|
+
{{#if yourRanking}}
|
|
40
40
|
<td class="list-element-striped" width="5%" style="text-align:center">
|
|
41
41
|
<a {{action 'moveToPreviousPage' rankingItem.id}} title="move to previous page"><span class="glyphicon glyphicon-chevron-left"></span></a>
|
|
42
42
|
<a {{action 'moveToNextPage' rankingItem.id}} title="move to next page"><span class="glyphicon glyphicon-chevron-right"></span></a>
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
{{/if}}
|
|
52
52
|
<td class="list-element-striped" width="15%" style="text-align:center;">
|
|
53
53
|
<div class="stars" style="white-space:nowrap;">
|
|
54
|
-
{{#if
|
|
54
|
+
{{#if yourRanking}}
|
|
55
55
|
<span class="5stars {{if rankingItem.is5StarClass 'active'}}" {{action 'updateStars' rankingItem.id rankingItem.stars 5}}></span>
|
|
56
56
|
<span class="4stars {{if rankingItem.is4StarClass 'active'}}" {{action 'updateStars' rankingItem.id rankingItem.stars 4}}></span>
|
|
57
57
|
<span class="3stars {{if rankingItem.is3StarClass 'active'}}" {{action 'updateStars' rankingItem.id rankingItem.stars 3}}></span>
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
{{/if}}
|
|
67
67
|
</div>
|
|
68
68
|
</td>
|
|
69
|
-
{{#if
|
|
69
|
+
{{#if yourRanking}}
|
|
70
70
|
<td width="3%" style="text-align:center;">
|
|
71
71
|
<span class="glyphicon glyphicon-remove" {{action 'destroy' rankingItem.id}}></span>
|
|
72
72
|
</td>
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
<nav>
|
|
2
2
|
<ul class="pagination">
|
|
3
|
-
{{#if
|
|
3
|
+
{{#if showFirstPageLink}}
|
|
4
4
|
<li class="first"><a {{action 'goToPage' 1}}>« First</a></li>
|
|
5
5
|
{{/if}}
|
|
6
6
|
|
|
7
|
-
{{#if
|
|
8
|
-
<li class="prev"><a {{action 'goToPage'
|
|
7
|
+
{{#if showPreviousPageLink}}
|
|
8
|
+
<li class="prev"><a {{action 'goToPage' previousPage}}>« Previous</a></li>
|
|
9
9
|
{{/if}}
|
|
10
10
|
|
|
11
|
-
{{#each
|
|
11
|
+
{{#each pages as |currentPage|}}
|
|
12
12
|
<li class="{{if currentPage.isCurrent 'active'}}"><a href="#" {{action 'goToPage' currentPage.number}}>{{currentPage.number}}</a></li>
|
|
13
13
|
{{/each}}
|
|
14
14
|
|
|
15
|
-
{{#if
|
|
16
|
-
<li class="next_page"><a {{action 'goToPage'
|
|
15
|
+
{{#if showNextPageLink}}
|
|
16
|
+
<li class="next_page"><a {{action 'goToPage' nextPage}}>Next »</a></li>
|
|
17
17
|
{{/if}}
|
|
18
18
|
|
|
19
|
-
{{#if
|
|
20
|
-
<li class="last next"><a {{action 'goToPage'
|
|
19
|
+
{{#if showLastPageLink}}
|
|
20
|
+
<li class="last next"><a {{action 'goToPage' totalPages}}>Last »</a></li>
|
|
21
21
|
{{/if}}
|
|
22
22
|
</ul>
|
|
23
23
|
</nav>
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
<h1>
|
|
2
|
-
{{name}}
|
|
2
|
+
{{model.name}}
|
|
3
3
|
vs.
|
|
4
4
|
{{input type="text" value=otherThingName placeholder="Other thing" data-autocomplete="/api/v1/things/autocomplete"}}
|
|
5
|
-
<button class="compare_button" {{action 'compare'}}>Compare</button>
|
|
5
|
+
<button class="btn btn-default compare_button" {{action 'compare'}}>Compare</button>
|
|
6
|
+
{{#if onComparisonList}}
|
|
7
|
+
<button class="btn btn-default" {{action 'removeFromComparisonList' model.name}}>{{t 'things.show.remove_from_comparison_list'}}</button>
|
|
8
|
+
{{else}}
|
|
9
|
+
<button class="btn btn-default" {{action 'addToComparisonList' model.name}}>{{t 'things.show.add_to_comparison_list'}}</button>
|
|
10
|
+
{{/if}}
|
|
11
|
+
<a {{action 'goToComparisonList'}} style="font-size:14px;">
|
|
12
|
+
{{t 'things.show.comparison_list'}} ({{thingComparisonListCount}})
|
|
13
|
+
</a>
|
|
6
14
|
</h1>
|
|
7
15
|
|
|
8
16
|
<ul class="nav nav-pills">
|
data/app/assets/javascripts/voluntary_ranking/templates/things_comparison_matrix.js.handlebars
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h1>{{t 'arguments.matrix.title' }}</h1>
|
|
2
|
+
|
|
3
|
+
<table class="table table-striped">
|
|
4
|
+
<thead>
|
|
5
|
+
<tr>
|
|
6
|
+
<th></th>
|
|
7
|
+
{{#each model.argumentables as |argumentable|}}
|
|
8
|
+
<th>{{#link-to 'thing' argumentable.name}}{{argumentable.name}}{{/link-to}}</th>
|
|
9
|
+
{{/each}}
|
|
10
|
+
</tr>
|
|
11
|
+
</thead>
|
|
12
|
+
<tbody>
|
|
13
|
+
{{#each model.matrix as |argument|}}
|
|
14
|
+
<tr>
|
|
15
|
+
<td>{{argument.topic_name}}</td>
|
|
16
|
+
{{#each argument.values as |value|}}
|
|
17
|
+
<td>{{value}}</td>
|
|
18
|
+
{{/each}}
|
|
19
|
+
</tr>
|
|
20
|
+
{{/each}}
|
|
21
|
+
</tbody>
|
|
22
|
+
</table>
|
|
@@ -9,7 +9,7 @@ class Api::V1::RankingsController < ActionController::Base
|
|
|
9
9
|
rankings = Ranking
|
|
10
10
|
rankings = Ranking.for_user(params[:user_name]) if params[:user_name].present?
|
|
11
11
|
rankings = Ranking.for_thing(params[:thing_id]) if params[:thing_id].present?
|
|
12
|
-
options[:json] = rankings.paginate page: params[:page], per_page:
|
|
12
|
+
options[:json] = rankings.paginate page: params[:page], per_page: 10, count: { group: 'rankings.id' }
|
|
13
13
|
|
|
14
14
|
options[:meta] = {
|
|
15
15
|
pagination: {
|
|
@@ -15,7 +15,7 @@ class Api::V1::ThingsController < ActionController::Base
|
|
|
15
15
|
|
|
16
16
|
def autocomplete
|
|
17
17
|
render json: (
|
|
18
|
-
Thing.order(:name).where("name LIKE ?", "%#{params[:term]}%").
|
|
18
|
+
Thing.order(:name).where("LOWER(name) LIKE ?", "%#{params[:term].downcase}%").
|
|
19
19
|
map{|t| { id: t.id, value: t.name }}
|
|
20
20
|
), root: false
|
|
21
21
|
end
|
data/app/models/ranking.rb
CHANGED
|
@@ -65,7 +65,7 @@ class Ranking < ActiveRecord::Base
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
Ranking.select("DISTINCT(#{attribute})").order(attribute).limit(10).
|
|
68
|
-
where("#{attribute} LIKE ?", "%#{term.strip}%").map(&attribute.to_sym).map{|v| { value: v }}
|
|
68
|
+
where("LOWER(#{attribute}) LIKE ?", "%#{term.strip.downcase}%").map(&attribute.to_sym).map{|v| { value: v }}
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
private
|
|
@@ -25,7 +25,11 @@ class UserRankingItem < ActiveRecord::Base
|
|
|
25
25
|
ranking_items = ranking_items.where('id <> ?', user_ranking_item_id) if user_ranking_item_id.present?
|
|
26
26
|
|
|
27
27
|
if stars.to_i >= 3
|
|
28
|
-
ranking_items.order('stars ASC, position DESC').where('stars >= ?', stars).first.try(:position).to_i + 1 || 1
|
|
28
|
+
position = ranking_items.order('stars ASC, position DESC').where('stars >= ?', stars).first.try(:position).to_i + 1 || 1
|
|
29
|
+
|
|
30
|
+
position -= 1 if user_ranking_item_id.present? && position > ranking_items_count
|
|
31
|
+
|
|
32
|
+
position
|
|
29
33
|
else
|
|
30
34
|
item = ranking_items.order('stars DESC, position ASC').where('stars <= ?', stars).first
|
|
31
35
|
|
data/config/routes.rb
CHANGED
|
@@ -3,15 +3,6 @@ Rails.application.routes.draw do
|
|
|
3
3
|
|
|
4
4
|
namespace :api, defaults: {format: 'json'} do
|
|
5
5
|
scope module: :v1, path: 'v1' do
|
|
6
|
-
# TODO: remove manual routing when get rid of this resource using root UsersController
|
|
7
|
-
resources :argument_topics, only: [] do
|
|
8
|
-
collection do
|
|
9
|
-
get :autocomplete
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
resources :arguments
|
|
14
|
-
|
|
15
6
|
resources :rankings
|
|
16
7
|
|
|
17
8
|
get '/rankings/attributes/:attribute/autocomplete', to: 'rankings#autocomplete_attribute'
|
|
@@ -25,7 +16,6 @@ Rails.application.routes.draw do
|
|
|
25
16
|
end
|
|
26
17
|
end
|
|
27
18
|
|
|
28
|
-
get '/things/:left_thing_name/vs/:right_thing_name/arguments', to: 'things/arguments#comparison'
|
|
29
19
|
get '/things/:thing_name/is_one_of_the/:adjective/:topic/:scope', to: 'ranking_items#show'
|
|
30
20
|
|
|
31
21
|
resources :user_ranking_items do
|
|
@@ -34,8 +24,6 @@ Rails.application.routes.draw do
|
|
|
34
24
|
put :move
|
|
35
25
|
end
|
|
36
26
|
end
|
|
37
|
-
|
|
38
|
-
resources :users
|
|
39
27
|
end
|
|
40
28
|
end
|
|
41
29
|
end
|
metadata
CHANGED
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: voluntary_ranking
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mathias Gawlista
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: voluntary
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.5.2
|
|
20
|
+
- - "<"
|
|
18
21
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
22
|
+
version: '1.0'
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.5.2
|
|
30
|
+
- - "<"
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
32
|
+
version: '1.0'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: voluntary-ember_js
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- - "
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.1.0
|
|
40
|
+
- - "<"
|
|
32
41
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
42
|
+
version: '1.0'
|
|
34
43
|
type: :runtime
|
|
35
44
|
prerelease: false
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
46
|
requirements:
|
|
38
|
-
- - "
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 0.1.0
|
|
50
|
+
- - "<"
|
|
39
51
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
52
|
+
version: '1.0'
|
|
41
53
|
- !ruby/object:Gem::Dependency
|
|
42
54
|
name: letter_opener
|
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -290,7 +302,7 @@ dependencies:
|
|
|
290
302
|
- - "~>"
|
|
291
303
|
- !ruby/object:Gem::Version
|
|
292
304
|
version: 3.0.9
|
|
293
|
-
description: 'Ranking plugin for #crowdsourcing gem voluntary: http://bit.ly/vr-0-0
|
|
305
|
+
description: 'Ranking plugin for #crowdsourcing gem voluntary: http://bit.ly/vr-0-1-0'
|
|
294
306
|
email:
|
|
295
307
|
- gawlista@gmail.com
|
|
296
308
|
executables: []
|
|
@@ -302,8 +314,8 @@ files:
|
|
|
302
314
|
- Rakefile
|
|
303
315
|
- app/assets/javascripts/voluntary_ranking/app.js
|
|
304
316
|
- app/assets/javascripts/voluntary_ranking/application.js
|
|
305
|
-
- app/assets/javascripts/voluntary_ranking/
|
|
306
|
-
- app/assets/javascripts/voluntary_ranking/components/
|
|
317
|
+
- app/assets/javascripts/voluntary_ranking/components/new_argument_component.js.coffee
|
|
318
|
+
- app/assets/javascripts/voluntary_ranking/components/ranking_items_collection_component.js.coffee
|
|
307
319
|
- app/assets/javascripts/voluntary_ranking/controllers/arguments/index_controller.js.coffee
|
|
308
320
|
- app/assets/javascripts/voluntary_ranking/controllers/arguments/new_controller.js.coffee
|
|
309
321
|
- app/assets/javascripts/voluntary_ranking/controllers/compare_things/arguments_controller.js.coffee
|
|
@@ -318,13 +330,9 @@ files:
|
|
|
318
330
|
- app/assets/javascripts/voluntary_ranking/controllers/user/rankings/show_controller.js.coffee
|
|
319
331
|
- app/assets/javascripts/voluntary_ranking/controllers/user_controller.js.coffee
|
|
320
332
|
- app/assets/javascripts/voluntary_ranking/controllers/user_ranking_controller.js.coffee
|
|
321
|
-
- app/assets/javascripts/voluntary_ranking/helpers/name_with_apostrophe_helper.js.coffee
|
|
322
333
|
- app/assets/javascripts/voluntary_ranking/helpers/stars_html_helper.js.coffee
|
|
323
|
-
- app/assets/javascripts/voluntary_ranking/mixins/has_current_user.js.coffee
|
|
324
334
|
- app/assets/javascripts/voluntary_ranking/mixins/pagination_controller.js.coffee
|
|
325
335
|
- app/assets/javascripts/voluntary_ranking/mixins/ranking_controller.js.coffee
|
|
326
|
-
- app/assets/javascripts/voluntary_ranking/mixins/singleton.js.coffee
|
|
327
|
-
- app/assets/javascripts/voluntary_ranking/models/argument.js.coffee
|
|
328
336
|
- app/assets/javascripts/voluntary_ranking/models/movie.js.coffee
|
|
329
337
|
- app/assets/javascripts/voluntary_ranking/models/ranking.js.coffee
|
|
330
338
|
- app/assets/javascripts/voluntary_ranking/models/ranking_item.js.coffee
|
|
@@ -340,6 +348,7 @@ files:
|
|
|
340
348
|
- app/assets/javascripts/voluntary_ranking/routes/rankings/index_route.js.coffee
|
|
341
349
|
- app/assets/javascripts/voluntary_ranking/routes/rankings/show_route.js.coffee
|
|
342
350
|
- app/assets/javascripts/voluntary_ranking/routes/thing_route.js.coffee
|
|
351
|
+
- app/assets/javascripts/voluntary_ranking/routes/things_comparison_matrix_route.js.coffee
|
|
343
352
|
- app/assets/javascripts/voluntary_ranking/routes/user_ranking_route.js.coffee
|
|
344
353
|
- app/assets/javascripts/voluntary_ranking/routes/user_route.js.coffee
|
|
345
354
|
- app/assets/javascripts/voluntary_ranking/templates/application.handlebars.erb
|
|
@@ -348,7 +357,6 @@ files:
|
|
|
348
357
|
- app/assets/javascripts/voluntary_ranking/templates/arguments/new.js.handlebars
|
|
349
358
|
- app/assets/javascripts/voluntary_ranking/templates/compare_things.js.handlebars
|
|
350
359
|
- app/assets/javascripts/voluntary_ranking/templates/compare_things/arguments.js.handlebars
|
|
351
|
-
- app/assets/javascripts/voluntary_ranking/templates/components/modal-dialog.js.handlebars
|
|
352
360
|
- app/assets/javascripts/voluntary_ranking/templates/components/rankings-component.handlebars
|
|
353
361
|
- app/assets/javascripts/voluntary_ranking/templates/index.js.handlebars
|
|
354
362
|
- app/assets/javascripts/voluntary_ranking/templates/navigation.js.handlebars
|
|
@@ -364,34 +372,24 @@ files:
|
|
|
364
372
|
- app/assets/javascripts/voluntary_ranking/templates/thing/index.js.handlebars
|
|
365
373
|
- app/assets/javascripts/voluntary_ranking/templates/things/show.arguments.js.handlebars
|
|
366
374
|
- app/assets/javascripts/voluntary_ranking/templates/things/show.js.handlebars
|
|
375
|
+
- app/assets/javascripts/voluntary_ranking/templates/things_comparison_matrix.js.handlebars
|
|
367
376
|
- app/assets/javascripts/voluntary_ranking/templates/user.js.handlebars
|
|
368
377
|
- app/assets/javascripts/voluntary_ranking/templates/user/rankings/details.js.handlebars
|
|
369
|
-
- app/assets/javascripts/voluntary_ranking/views/application/index_view.js.coffee
|
|
370
|
-
- app/assets/javascripts/voluntary_ranking/views/arguments/new_view.js.coffee
|
|
371
|
-
- app/assets/javascripts/voluntary_ranking/views/index_view.js.coffee
|
|
372
|
-
- app/assets/javascripts/voluntary_ranking/views/ranking_items/colllection_view.js.coffee
|
|
373
|
-
- app/assets/javascripts/voluntary_ranking/views/shared/pagination.js
|
|
374
378
|
- app/assets/stylesheets/voluntary_ranking/application.css
|
|
375
379
|
- app/assets/stylesheets/voluntary_ranking/base.css.sass
|
|
376
380
|
- app/assets/stylesheets/voluntary_ranking/bootstrap_and_overrides.css.sass
|
|
377
381
|
- app/assets/stylesheets/voluntary_ranking/stars.css.sass
|
|
378
382
|
- app/assets/stylesheets/voluntary_ranking/twitter-typeahead.css.sass
|
|
379
|
-
- app/controllers/api/v1/argument_topics_controller.rb
|
|
380
|
-
- app/controllers/api/v1/arguments_controller.rb
|
|
381
383
|
- app/controllers/api/v1/ranking_items_controller.rb
|
|
382
384
|
- app/controllers/api/v1/rankings_controller.rb
|
|
383
|
-
- app/controllers/api/v1/things/arguments_controller.rb
|
|
384
385
|
- app/controllers/api/v1/things_controller.rb
|
|
385
386
|
- app/controllers/api/v1/user_ranking_items_controller.rb
|
|
386
387
|
- app/controllers/api/v1/users_controller.rb
|
|
387
388
|
- app/controllers/product/ranking_controller.rb
|
|
388
|
-
- app/models/argument.rb
|
|
389
|
-
- app/models/argument_topic.rb
|
|
390
389
|
- app/models/product/ranking.rb
|
|
391
390
|
- app/models/ranking.rb
|
|
392
391
|
- app/models/ranking_item.rb
|
|
393
392
|
- app/models/user_ranking_item.rb
|
|
394
|
-
- app/serializers/argument_serializer.rb
|
|
395
393
|
- app/serializers/base_ranking_item_serializer.rb
|
|
396
394
|
- app/serializers/ranking_item_serializer.rb
|
|
397
395
|
- app/serializers/user_ranking_item_serializer.rb
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Volontariat.Singleton = Em.Mixin.create(
|
|
2
|
-
current: ->
|
|
3
|
-
@_current = @createCurrent() unless @_current
|
|
4
|
-
@_current
|
|
5
|
-
|
|
6
|
-
createCurrent: ->
|
|
7
|
-
@create {}
|
|
8
|
-
|
|
9
|
-
currentProp: (property, value) ->
|
|
10
|
-
instance = @current()
|
|
11
|
-
return unless instance
|
|
12
|
-
if typeof (value) isnt "undefined"
|
|
13
|
-
instance.set property, value
|
|
14
|
-
value
|
|
15
|
-
else
|
|
16
|
-
instance.get property
|
|
17
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Volontariat.ApplicationIndexView = Ember.View.extend()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Volontariat.IndexView = Ember.View.extend()
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class Api::V1::ArgumentTopicsController < ActionController::Base
|
|
2
|
-
include Voluntary::V1::BaseController
|
|
3
|
-
|
|
4
|
-
respond_to :json
|
|
5
|
-
|
|
6
|
-
def autocomplete
|
|
7
|
-
render json: (
|
|
8
|
-
ArgumentTopic.order(:name).where("name LIKE ?", "%#{params[:term]}%").
|
|
9
|
-
map{|t| { id: t.id, value: t.name }}
|
|
10
|
-
), root: false
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
class Api::V1::ArgumentsController < ActionController::Base
|
|
2
|
-
include Voluntary::V1::BaseController
|
|
3
|
-
|
|
4
|
-
respond_to :json
|
|
5
|
-
|
|
6
|
-
def index
|
|
7
|
-
options = {}
|
|
8
|
-
|
|
9
|
-
arguments = Argument
|
|
10
|
-
arguments = Argument.where(thing_id: params[:thing_id]) if params[:thing_id].present?
|
|
11
|
-
options[:json] = arguments.paginate(page: params[:page], per_page: 10)
|
|
12
|
-
|
|
13
|
-
options[:meta] = {
|
|
14
|
-
pagination: {
|
|
15
|
-
total_pages: options[:json].total_pages, current_page: options[:json].current_page,
|
|
16
|
-
previous_page: options[:json].previous_page, next_page: options[:json].next_page
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
respond_with do |format|
|
|
21
|
-
format.json { render options }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def create
|
|
26
|
-
raise CanCan::AccessDenied if current_user.blank?
|
|
27
|
-
|
|
28
|
-
respond_to do |format|
|
|
29
|
-
format.json { render json: Argument.create_with_topic(params[:argument]) }
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
class Api::V1::Things::ArgumentsController < ActionController::Base
|
|
2
|
-
include Voluntary::V1::BaseController
|
|
3
|
-
|
|
4
|
-
respond_to :json
|
|
5
|
-
|
|
6
|
-
def comparison
|
|
7
|
-
options = {}
|
|
8
|
-
|
|
9
|
-
arguments = Argument.compare_two_things(params[:side], params[:left_thing_name], params[:right_thing_name]).
|
|
10
|
-
paginate(page: params[:page], per_page: 10)
|
|
11
|
-
|
|
12
|
-
options[:json] = arguments.map do |argument_comparison|
|
|
13
|
-
hash = {
|
|
14
|
-
left: { id: argument_comparison.id, value: argument_comparison.value },
|
|
15
|
-
right: { id: argument_comparison.right_id, value: argument_comparison.right_value },
|
|
16
|
-
topic: { id: argument_comparison.topic_id, name: argument_comparison.topic_name }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if params[:side] == 'right'
|
|
20
|
-
left = hash[:left].clone
|
|
21
|
-
right = hash[:right].clone
|
|
22
|
-
hash[:left] = right
|
|
23
|
-
hash[:right] = left
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
hash
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
options[:meta] = {
|
|
30
|
-
pagination: {
|
|
31
|
-
total_pages: arguments.total_pages, current_page: arguments.current_page,
|
|
32
|
-
previous_page: arguments.previous_page, next_page: arguments.next_page
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
respond_with do |format|
|
|
37
|
-
format.json { render options }
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
data/app/models/argument.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
class Argument < ActiveRecord::Base
|
|
2
|
-
belongs_to :topic, class_name: 'ArgumentTopic'
|
|
3
|
-
belongs_to :thing
|
|
4
|
-
|
|
5
|
-
scope :compare_two_things, ->(side, left_thing_name, right_thing_name) do
|
|
6
|
-
left_thing_name, right_thing_name = right_thing_name, left_thing_name if side == 'right'
|
|
7
|
-
|
|
8
|
-
left_thing = Thing.where('LOWER(name) = ?', left_thing_name.downcase).first
|
|
9
|
-
right_thing = Thing.where('LOWER(name) = ?', right_thing_name.downcase).first
|
|
10
|
-
|
|
11
|
-
scope = joins(:topic).select('arguments.id, arguments.value, arguments.topic_id, argument_topics.name AS topic_name, arguments2.id AS right_id, arguments2.value AS right_value').
|
|
12
|
-
joins("#{side == 'both' ? 'INNER' : 'LEFT'} JOIN arguments arguments2 ON arguments2.thing_id = #{sanitize(right_thing.id)} AND arguments2.topic_id = arguments.topic_id")
|
|
13
|
-
scope = scope.where('arguments2.id IS NULL') unless side == 'both'
|
|
14
|
-
scope.where('arguments.thing_id = ?', left_thing.id)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
validates :topic_id, presence: true
|
|
18
|
-
validates :thing_id, presence: true, uniqueness: { scope: :topic_id }
|
|
19
|
-
validates :value, presence: true
|
|
20
|
-
|
|
21
|
-
attr_accessible :topic_id, :thing_id, :value
|
|
22
|
-
|
|
23
|
-
def self.create_with_topic(attributes)
|
|
24
|
-
topic = ArgumentTopic.where('LOWER(name) = ?', attributes[:topic_name].to_s.strip.downcase).first
|
|
25
|
-
|
|
26
|
-
unless topic
|
|
27
|
-
topic = ArgumentTopic.create(name: attributes[:topic_name].to_s.strip)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
if topic.valid?
|
|
31
|
-
thing_id = if attributes[:thing_name].present?
|
|
32
|
-
Thing.where('LOWER(name) = ?', attributes[:thing_name].downcase).first.id
|
|
33
|
-
else
|
|
34
|
-
Thing.where(id: attributes[:thing_id]).first.try(:id)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
argument = Argument.create(topic_id: topic.id, thing_id: thing_id, value: attributes[:value])
|
|
38
|
-
|
|
39
|
-
if argument.valid?
|
|
40
|
-
argument
|
|
41
|
-
else
|
|
42
|
-
{ errors: argument.errors.to_hash }
|
|
43
|
-
end
|
|
44
|
-
else
|
|
45
|
-
{ errors: { topic: topic.errors.to_hash } }
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|