mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 13:44:23 +08:00
Migration fix, additional endpoints, cleanup [SCI-8947]
This commit is contained in:
parent
633abf69c0
commit
11fb166a0c
5 changed files with 33 additions and 38 deletions
|
@ -4,7 +4,7 @@ class ResultsController < ApplicationController
|
|||
skip_before_action :verify_authenticity_token, only: %i(create destroy)
|
||||
|
||||
before_action :load_my_module
|
||||
before_action :load_vars, only: :destroy
|
||||
before_action :load_vars, only: %i(destroy elements assets)
|
||||
before_action :check_destroy_permissions, only: :destroy
|
||||
|
||||
def index
|
||||
|
@ -32,6 +32,18 @@ class ResultsController < ApplicationController
|
|||
render json: result
|
||||
end
|
||||
|
||||
def elements
|
||||
render json: @result.result_orderable_elements.order(:position),
|
||||
each_serializer: ResultOrderableElementSerializer,
|
||||
user: current_user
|
||||
end
|
||||
|
||||
def assets
|
||||
render json: @result.assets,
|
||||
each_serializer: AssetSerializer,
|
||||
user: current_user
|
||||
end
|
||||
|
||||
def destroy
|
||||
result_type = if @result.is_text
|
||||
t('activities.result_type.text')
|
||||
|
@ -79,7 +91,7 @@ class ResultsController < ApplicationController
|
|||
end
|
||||
|
||||
def load_vars
|
||||
@result = Result.find_by_id(params[:id])
|
||||
@result = @my_module.results.find(params[:id])
|
||||
|
||||
return render_403 unless @result
|
||||
|
||||
|
|
|
@ -23,34 +23,9 @@
|
|||
<i class="sn-icon sn-icon-sort"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="sortDropdown">
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('updated_at_asc')">
|
||||
{{ i18n.t('my_modules.results.sorts.updated_at_asc')}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('updated_at_desc')">
|
||||
{{ i18n.t('my_modules.results.sorts.updated_at_desc')}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('created_at_asc')">
|
||||
{{ i18n.t('my_modules.results.sorts.created_at_asc')}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('created_at_desc')">
|
||||
{{ i18n.t('my_modules.results.sorts.created_at_desc')}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('name_asc')">
|
||||
{{ i18n.t('my_modules.results.sorts.name_asc')}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="cursor-pointer" @click="setSort('name_desc')">
|
||||
{{ i18n.t('my_modules.results.sorts.name_desc')}}
|
||||
<li v-for="sort in sorts" :key="sort">
|
||||
<a class="cursor-pointer" @click="setSort(sort)">
|
||||
{{ i18n.t(`my_modules.results.sorts.${sort}`)}}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -60,11 +35,23 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
const SORTS = [
|
||||
'updated_at_asc',
|
||||
'updated_at_desc',
|
||||
'created_at_asc',
|
||||
'created_at_desc',
|
||||
'name_asc',
|
||||
'name_desc'
|
||||
];
|
||||
|
||||
export default {
|
||||
name: 'ResultsToolbar',
|
||||
props: {
|
||||
sort: { type: String, required: true }
|
||||
},
|
||||
created() {
|
||||
this.sorts = SORTS;
|
||||
},
|
||||
methods: {
|
||||
setSort(sort) {
|
||||
this.$emit('setSort', sort);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
class ResultAsset < ApplicationRecord
|
||||
belongs_to :result, inverse_of: :result_assets, touch: true
|
||||
belongs_to :asset, inverse_of: :result_asset, dependent: :destroy
|
||||
has_one :result_orderable_element, as: :orderable, dependent: :destroy
|
||||
|
||||
def space_taken
|
||||
asset.present? ? asset.estimated_size : 0
|
||||
|
|
|
@ -534,7 +534,10 @@ Rails.application.routes.draw do
|
|||
get 'tags/edit', to: 'my_module_tags#index_edit'
|
||||
get 'users/edit', to: 'user_my_modules#index_edit'
|
||||
|
||||
resources :results, only: %i(index show create update destroy)
|
||||
resources :results, only: %i(index show create update destroy) do
|
||||
get :elements
|
||||
get :assets
|
||||
end
|
||||
end
|
||||
|
||||
resources :steps, only: %i(index update destroy show) do
|
||||
|
|
|
@ -23,12 +23,6 @@ class CreateResultOrderableElements < ActiveRecord::Migration[7.0]
|
|||
'result_orderable_elements(result_id, position, orderable_type, orderable_id, created_at, updated_at) ' \
|
||||
'SELECT result_id, 0, \'ResultTable\', id, NOW(), NOW() FROM result_tables;'
|
||||
)
|
||||
|
||||
ActiveRecord::Base.connection.execute(
|
||||
'INSERT INTO ' \
|
||||
'result_orderable_elements(result_id, position, orderable_type, orderable_id, created_at, updated_at) ' \
|
||||
'SELECT result_id, 0, \'ResultAsset\', id, NOW(), NOW() FROM result_assets;'
|
||||
)
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
Loading…
Add table
Reference in a new issue