diff --git a/Gemfile.lock b/Gemfile.lock index 7b505cf5ea..61b36bbff2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -119,7 +119,7 @@ GEM closure_tree (7.1.0) activerecord (>= 4.2.10) with_advisory_lock (>= 4.0.0) - coderay (1.1.2) + coderay (1.1.3) concurrent-ruby (1.1.6) coveralls (0.8.23) json (>= 1.8, < 3) @@ -161,13 +161,13 @@ GEM factory_bot_rails (5.2.0) factory_bot (~> 5.2.0) railties (>= 4.2.0) - faker (2.11.0) + faker (2.12.0) i18n (>= 1.6, < 2) faraday (0.17.3) multipart-post (>= 1.2, < 3) faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) - ffi (1.12.2) + ffi (1.13.0) ffi-geos (2.1.0) ffi (>= 1.0.0) formatador (0.2.5) @@ -210,7 +210,7 @@ GEM hashery (2.1.2) hashie (3.6.0) hiredis (0.6.3) - i18n (1.8.2) + i18n (1.8.3) concurrent-ruby (~> 1.0) indefinite_article (0.2.4) activesupport @@ -362,7 +362,7 @@ GEM rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) - rdf (3.1.1) + rdf (3.1.2) hamster (~> 3.0) link_header (~> 0.0, >= 0.0.8) rdoc (6.2.1) @@ -413,10 +413,11 @@ GEM rspec-support (3.9.3) rtesseract (3.0.5) nokogiri - rubocop (0.84.0) + rubocop (0.85.0) parallel (~> 1.10) parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) rexml rubocop-ast (>= 0.0.3) ruby-progressbar (~> 1.7) @@ -437,7 +438,7 @@ GEM ruby-units (2.3.1) rubyzip (2.3.0) safe_yaml (1.0.5) - sassc (2.3.0) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -532,7 +533,7 @@ GEM semantic_range (>= 2.3.0) websocket-driver (0.7.2) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) + websocket-extensions (0.1.5) wikidata-client (0.0.12) excon (~> 0.40) faraday (~> 0.9) diff --git a/app/controllers/observation_matrix_columns_controller.rb b/app/controllers/observation_matrix_columns_controller.rb index 614b9be423..dc191000ad 100644 --- a/app/controllers/observation_matrix_columns_controller.rb +++ b/app/controllers/observation_matrix_columns_controller.rb @@ -2,6 +2,7 @@ class ObservationMatrixColumnsController < ApplicationController include DataControllerConfiguration::ProjectDataControllerConfiguration before_action :set_observation_matrix_column, only: [:show] + after_action -> { set_pagination_headers(:observation_matrix_columns) }, only: [:index], if: :json_request? # GET /matrix_columns # GET /matrix_columns.json @@ -12,7 +13,10 @@ def index render '/shared/data/all/index' end format.json { - @observation_matrix_columns = ObservationMatrixColumn.where(filter_params).where(project_id: sessions_current_project_id).order('observation_matrix_columns.position') + @observation_matrix_columns = ObservationMatrixColumn.where(filter_params) + .where(project_id: sessions_current_project_id) + .order('observation_matrix_columns.position') + .page(params[:page]).per(params[:per]) } end end diff --git a/app/javascript/vue/tasks/descriptor/app.vue b/app/javascript/vue/tasks/descriptor/app.vue index 04873e4578..5c8d6c6ac9 100644 --- a/app/javascript/vue/tasks/descriptor/app.vue +++ b/app/javascript/vue/tasks/descriptor/app.vue @@ -77,7 +77,7 @@ @@ -201,14 +201,14 @@ export default { short_name: undefined } }, - saveDescriptor (descriptor) { + saveDescriptor (descriptor, redirect = true) { this.saving = true if (this.descriptor.id) { UpdateDescriptor(descriptor).then(response => { this.descriptor = response this.saving = false TW.workbench.alert.create('Descriptor was successfully updated.', 'notice') - if (this.matrix) { + if (this.matrix && redirect) { window.open(`/tasks/observation_matrices/new_matrix/${this.matrixId}`, '_self') } }, rejected => { @@ -221,7 +221,7 @@ export default { this.setParameters() TW.workbench.alert.create('Descriptor was successfully created.', 'notice') if (this.matrix) { - this.addToMatrix(this.descriptor) + this.addToMatrix(this.descriptor, redirect) } }, rejected => { this.saving = false @@ -235,7 +235,7 @@ export default { TW.workbench.alert.create('Descriptor was successfully deleted.', 'notice') }) }, - addToMatrix (descriptor) { + addToMatrix (descriptor, redirect) { const data = { descriptor_id: descriptor.id, observation_matrix_id: this.matrix.id, @@ -243,7 +243,9 @@ export default { } CreateObservationMatrixColumn(data).then(() => { TW.workbench.alert.create('Descriptor was successfully added to the matrix.', 'notice') - window.open(`/tasks/observation_matrices/new_matrix/${this.matrixId}`, '_self') + if (redirect) { + window.open(`/tasks/observation_matrices/new_matrix/${this.matrixId}`, '_self') + } }) }, loadMatrix (id) { diff --git a/app/javascript/vue/tasks/new_matrix/app.vue b/app/javascript/vue/tasks/new_matrix/app.vue index 11d8c8bcce..83d248813b 100644 --- a/app/javascript/vue/tasks/new_matrix/app.vue +++ b/app/javascript/vue/tasks/new_matrix/app.vue @@ -1,15 +1,25 @@ \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/request/resources.js b/app/javascript/vue/tasks/new_matrix/request/resources.js index b31bf5130b..830913bf54 100644 --- a/app/javascript/vue/tasks/new_matrix/request/resources.js +++ b/app/javascript/vue/tasks/new_matrix/request/resources.js @@ -1,31 +1,4 @@ -import Vue from 'vue' -import VueResource from 'vue-resource' - -Vue.use(VueResource) - -const ajaxCall = function (type, url, data = null) { - Vue.http.headers.common['X-CSRF-Token'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content') - return new Promise(function (resolve, reject) { - Vue.http[type](url, data).then(response => { - return resolve(response.body) - }, response => { - handleError(response.body) - return reject(response) - }) - }) -} - -const handleError = function (json) { - if (typeof json !== 'object') return - let errors = Object.keys(json) - let errorMessage = '' - - errors.forEach(function (item) { - errorMessage += json[item].join('
') - }) - - TW.workbench.alert.create(errorMessage, 'error') -} +import ajaxCall from 'helpers/ajaxCall.js' const GetObservationMatrices = () => { return ajaxCall('get', '/observation_matrices.json') @@ -40,27 +13,27 @@ const UpdateMatrix = function (id, data) { } const GetMatrixObservation = function(id) { - return ajaxCall('get',`/observation_matrices/${id}.json`) + return ajaxCall('get',`/observation_matrices/${id}.json`, { per: 500 }) } -const GetMatrixObservationRows = function(id) { - return ajaxCall('get',`/observation_matrices/${id}/observation_matrix_rows.json`) +const GetMatrixObservationRows = function (id, params = undefined) { + return ajaxCall('get', `/observation_matrices/${id}/observation_matrix_rows.json`, { params: params }) } -const GetMatrixObservationRowsDynamic = function(id) { +const GetMatrixObservationRowsDynamic = function (id) { return new Promise((resolve, reject) => { let promises = [] promises.push(ajaxCall('get',`/observation_matrices/${id}/observation_matrix_row_items.json?type=ObservationMatrixRowItem::TaggedRowItem`)) promises.push(ajaxCall('get',`/observation_matrices/${id}/observation_matrix_row_items.json?type=ObservationMatrixRowItem::TaxonNameRowItem`)) Promise.all(promises).then((response) => { - return resolve(response[0].concat(response[1])) + return resolve(response[0].body.concat(response[1].body)) }) }) } -const GetMatrixObservationColumns = function(id) { - return ajaxCall('get',`/observation_matrices/${id}/observation_matrix_columns.json`) +const GetMatrixObservationColumns = function(id, params) { + return ajaxCall('get', `/observation_matrices/${id}/observation_matrix_columns.json`, { params: params }) } const GetMatrixObservationColumnsDynamic = function(id) { diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/createRowItem.js b/app/javascript/vue/tasks/new_matrix/store/actions/createRowItem.js index cd3416cefc..061adfd301 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/createRowItem.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/createRowItem.js @@ -4,7 +4,7 @@ import ActionNames from '../actions/actionNames' export default function ({ commit, state, dispatch }, data) { return new Promise((resolve, reject) => { CreateRowItem({ observation_matrix_row_item: data }).then(response => { - dispatch(ActionNames.GetMatrixObservationRows, state.matrix.id) + dispatch(ActionNames.GetMatrixObservationRows, { per: 500 }) dispatch(ActionNames.GetMatrixObservationRowsDynamic, state.matrix.id) TW.workbench.alert.create('Row item was successfully created.', 'notice') return resolve(response) diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnDynamicItems.js b/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnDynamicItems.js index 9958c4366f..fdf419bfa3 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnDynamicItems.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnDynamicItems.js @@ -3,11 +3,11 @@ import { GetMatrixObservationColumnsDynamic } from '../../request/resources' export default function ({ commit, state }, id) { return new Promise((resolve, reject) => { - return GetMatrixObservationColumnsDynamic(id).then(columns => { - commit(MutationNames.SetMatrixColumnsDynamic, columns) - return resolve(columns) - }, (response) => { - return reject(response) - }) + return GetMatrixObservationColumnsDynamic(id).then(response => { + commit(MutationNames.SetMatrixColumnsDynamic, response.body) + return resolve(response) + }, (response) => { + return reject(response) + }) }) -} \ No newline at end of file +} diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnItems.js b/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnItems.js index 926d8a2a3f..fec89afbe7 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnItems.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/loadColumnItems.js @@ -1,13 +1,18 @@ import { MutationNames } from '../mutations/mutations' import { GetMatrixObservationColumns } from '../../request/resources' +import getPagination from 'helpers/getPagination.js' -export default function ({ commit, state }, id) { +export default function ({ commit, state }, params = {}) { return new Promise((resolve, reject) => { - return GetMatrixObservationColumns(id).then(columns => { - commit(MutationNames.SetMatrixColumns, columns) - return resolve(columns) - }, (response) => { - return reject(response) - }) + state.settings.loadingColumns = true + return GetMatrixObservationColumns(state.matrix.id, Object.assign({}, params, state.configParams)).then(response => { + commit(MutationNames.SetMatrixColumns, response.body) + commit(MutationNames.SetColumnFixedPagination, getPagination(response)) + state.settings.loadingColumns = false + return resolve(response) + }, (response) => { + state.settings.loadingColumns = false + return reject(response) + }) }) -} \ No newline at end of file +} diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/loadMatrix.js b/app/javascript/vue/tasks/new_matrix/store/actions/loadMatrix.js index 39e3e4f354..677c64bde8 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/loadMatrix.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/loadMatrix.js @@ -2,11 +2,11 @@ import { MutationNames } from '../mutations/mutations' import ActionNames from '../actions/actionNames' import { GetMatrixObservation } from '../../request/resources' -export default function ({ commit, state, dispatch }, id) { +export default function ({ commit, dispatch }, id) { return new Promise((resolve, reject) => { GetMatrixObservation(id).then(response => { - commit(MutationNames.SetMatrix, response) - dispatch(ActionNames.GetMatrixObservationRows, id) + commit(MutationNames.SetMatrix, response.body) + dispatch(ActionNames.GetMatrixObservationRows, { per: 500 }) dispatch(ActionNames.GetMatrixObservationColumns, id) dispatch(ActionNames.GetMatrixObservationRowsDynamic, id) dispatch(ActionNames.GetMatrixObservationColumnsDynamic, id) diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/loadRowDynamicItems.js b/app/javascript/vue/tasks/new_matrix/store/actions/loadRowDynamicItems.js index d52e765885..91f5273873 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/loadRowDynamicItems.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/loadRowDynamicItems.js @@ -3,11 +3,11 @@ import { GetMatrixObservationRowsDynamic } from '../../request/resources' export default function ({ commit, state }, id) { return new Promise((resolve, reject) => { - return GetMatrixObservationRowsDynamic(id).then(rows => { - commit(MutationNames.SetMatrixRowsDynamic, rows) - return resolve(rows) - }, (response) => { - return reject(response) - }) + return GetMatrixObservationRowsDynamic(id).then(response => { + commit(MutationNames.SetMatrixRowsDynamic, response) + return resolve(response) + }, (response) => { + return reject(response) + }) }) -} \ No newline at end of file +} diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/loadRowItems.js b/app/javascript/vue/tasks/new_matrix/store/actions/loadRowItems.js index fc19716a31..300c499d02 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/loadRowItems.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/loadRowItems.js @@ -1,13 +1,18 @@ import { MutationNames } from '../mutations/mutations' import { GetMatrixObservationRows } from '../../request/resources' +import getPagination from 'helpers/getPagination.js' -export default function ({ commit, state }, id) { +export default function ({ commit, state }, params = {}) { return new Promise((resolve, reject) => { - return GetMatrixObservationRows(id).then(rows => { - commit(MutationNames.SetMatrixRows, rows) - return resolve(rows) - }, (response) => { - return reject(response) - }) + state.settings.loadingRows = true + return GetMatrixObservationRows(state.matrix.id, Object.assign({}, params, state.configParams)).then(response => { + commit(MutationNames.SetMatrixRows, response.body) + commit(MutationNames.SetRowFixedPagination, getPagination(response)) + state.settings.loadingRows = false + return resolve(response) + }, (response) => { + state.settings.loadingRows = false + return reject(response) + }) }) -} \ No newline at end of file +} diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/removeColumn.js b/app/javascript/vue/tasks/new_matrix/store/actions/removeColumn.js index a8cfed961d..75a444a2d0 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/removeColumn.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/removeColumn.js @@ -3,12 +3,12 @@ import ActionNames from '../actions/actionNames' export default function ({ commit, state, dispatch }, id) { return new Promise((resolve, reject) => { - return RemoveColumn(id).then(response => { - dispatch(ActionNames.GetMatrixObservationColumns, state.matrix.id) - dispatch(ActionNames.GetMatrixObservationColumnsDynamic, state.matrix.id) - return resolve(response) - }, (response) => { - return reject(response) - }) + return RemoveColumn(id).then(response => { + dispatch(ActionNames.GetMatrixObservationColumns, state.matrix.id) + dispatch(ActionNames.GetMatrixObservationColumnsDynamic, state.matrix.id) + return resolve(response) + }, (response) => { + return reject(response) + }) }) -} \ No newline at end of file +} diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/removeRow.js b/app/javascript/vue/tasks/new_matrix/store/actions/removeRow.js index 8c62fe3a8f..6409db4e7f 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/removeRow.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/removeRow.js @@ -3,12 +3,12 @@ import ActionNames from '../actions/actionNames' export default function ({ commit, state, dispatch }, id) { return new Promise((resolve, reject) => { - return RemoveRow(id).then(response => { - dispatch(ActionNames.GetMatrixObservationRows, state.matrix.id) - dispatch(ActionNames.GetMatrixObservationRowsDynamic, state.matrix.id) - return resolve(response) - }, (response) => { - return reject(response) - }) + return RemoveRow(id).then(response => { + dispatch(ActionNames.GetMatrixObservationRows, { per: 500 }) + dispatch(ActionNames.GetMatrixObservationRowsDynamic, state.matrix.id) + return resolve(response) + }, (response) => { + return reject(response) + }) }) } \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/store/actions/updateMatrix.js b/app/javascript/vue/tasks/new_matrix/store/actions/updateMatrix.js index 9994839400..0153fe9e5b 100644 --- a/app/javascript/vue/tasks/new_matrix/store/actions/updateMatrix.js +++ b/app/javascript/vue/tasks/new_matrix/store/actions/updateMatrix.js @@ -8,7 +8,7 @@ export default function ({ commit, state, dispatch }) { } UpdateMatrix(state.matrix.id, data).then(response => { TW.workbench.alert.create('Matrix was successfully updated.', 'notice') - return resolve(response) + return resolve(response.body) }) }) } \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/store/getters/getColumnFixedPagination.js b/app/javascript/vue/tasks/new_matrix/store/getters/getColumnFixedPagination.js new file mode 100644 index 0000000000..ef4680538e --- /dev/null +++ b/app/javascript/vue/tasks/new_matrix/store/getters/getColumnFixedPagination.js @@ -0,0 +1,3 @@ +export default function (state) { + return state.columnFixedPagination +} \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/store/getters/getRowFixedPagination.js b/app/javascript/vue/tasks/new_matrix/store/getters/getRowFixedPagination.js new file mode 100644 index 0000000000..328e02fec8 --- /dev/null +++ b/app/javascript/vue/tasks/new_matrix/store/getters/getRowFixedPagination.js @@ -0,0 +1,3 @@ +export default function (state) { + return state.rowFixedPagination +} \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/store/getters/getSettings.js b/app/javascript/vue/tasks/new_matrix/store/getters/getSettings.js new file mode 100644 index 0000000000..c1bfcc0e50 --- /dev/null +++ b/app/javascript/vue/tasks/new_matrix/store/getters/getSettings.js @@ -0,0 +1,3 @@ +export default function (state) { + return state.settings +} \ No newline at end of file diff --git a/app/javascript/vue/tasks/new_matrix/store/getters/getters.js b/app/javascript/vue/tasks/new_matrix/store/getters/getters.js index 931fda1b2a..25af14cb96 100644 --- a/app/javascript/vue/tasks/new_matrix/store/getters/getters.js +++ b/app/javascript/vue/tasks/new_matrix/store/getters/getters.js @@ -5,6 +5,9 @@ import getMatrixRowsDynamic from './getMatrixRowsDynamic' import getMatrixColumnsDynamic from './getMatrixColumnsDynamic' import getMatrixView from './getMatrixView' import getMatrixMode from './getMatrixMode' +import getRowFixedPagination from './getRowFixedPagination' +import getColumnFixedPagination from './getColumnFixedPagination' +import getSettings from './getSettings' const GetterNames = { GetMatrix: 'getMatrix', @@ -13,7 +16,10 @@ const GetterNames = { GetMatrixView: 'getMatrixView', GetMatrixMode: 'getMatrixMode', GetMatrixColumns: 'getMatrixColumns', - GetMatrixColumnsDynamic: 'getMatrixColumnsDynamic' + GetMatrixColumnsDynamic: 'getMatrixColumnsDynamic', + GetRowFixedPagination: 'getRowFixedPagination', + getColumnFixedPagination: 'getColumnFixedPagination', + getSettings: 'getSettings' } const GetterFunctions = { @@ -23,7 +29,10 @@ const GetterFunctions = { [GetterNames.GetMatrixView]: getMatrixView, [GetterNames.GetMatrixMode]: getMatrixMode, [GetterNames.GetMatrixColumns]: getMatrixColumns, - [GetterNames.GetMatrixColumnsDynamic]: getMatrixColumnsDynamic + [GetterNames.GetMatrixColumnsDynamic]: getMatrixColumnsDynamic, + [GetterNames.GetRowFixedPagination]: getRowFixedPagination, + [GetterNames.GetColumnFixedPagination]: getColumnFixedPagination, + [GetterNames.GetSettings]: getSettings } export { diff --git a/app/javascript/vue/tasks/new_matrix/store/mutations/mutations.js b/app/javascript/vue/tasks/new_matrix/store/mutations/mutations.js index 61da3dbd57..718eada5d9 100644 --- a/app/javascript/vue/tasks/new_matrix/store/mutations/mutations.js +++ b/app/javascript/vue/tasks/new_matrix/store/mutations/mutations.js @@ -7,6 +7,8 @@ import setMatrixView from './setMatrixView' import setMatrixMode from './setMatrixMode' import setMatrixColumnsDynamic from './setMatrixColumnsDynamic' import setMatrixRowsDynamic from './setMatrixRowsDynamic' +import setRowFixedPagination from './setRowFixedPagination' +import setColumnFixedPagination from './setColumnFixedPagination' const MutationNames = { SetMatrix: 'setMatrix', @@ -17,6 +19,8 @@ const MutationNames = { SetMatrixRows: 'setMatrixRows', SetMatrixView: 'setMatrixView', SetMatrixMode: 'setMatrixMode', + SetRowFixedPagination: 'setRowFixedPagination', + SetColumnFixedPagination: 'setColumnFixedPagination', AddRowItem: 'addRowItem' } @@ -30,6 +34,8 @@ const MutationFunctions = { [MutationNames.SetMatrixView]: setMatrixView, [MutationNames.SetMatrixMode]: setMatrixMode, [MutationNames.AddRowItem]: addRowItem, + [MutationNames.SetRowFixedPagination]: setRowFixedPagination, + [MutationNames.SetColumnFixedPagination]: setColumnFixedPagination } export { diff --git a/app/javascript/vue/tasks/new_matrix/store/mutations/setColumnFixedPagination.js b/app/javascript/vue/tasks/new_matrix/store/mutations/setColumnFixedPagination.js new file mode 100644 index 0000000000..e056582cb3 --- /dev/null +++ b/app/javascript/vue/tasks/new_matrix/store/mutations/setColumnFixedPagination.js @@ -0,0 +1,3 @@ +export default function (state, value) { + state.columnFixedPagination = value +} diff --git a/app/javascript/vue/tasks/new_matrix/store/mutations/setRowFixedPagination.js b/app/javascript/vue/tasks/new_matrix/store/mutations/setRowFixedPagination.js new file mode 100644 index 0000000000..170fdfcf38 --- /dev/null +++ b/app/javascript/vue/tasks/new_matrix/store/mutations/setRowFixedPagination.js @@ -0,0 +1,3 @@ +export default function (state, value) { + state.rowFixedPagination = value +} diff --git a/app/javascript/vue/tasks/new_matrix/store/store.js b/app/javascript/vue/tasks/new_matrix/store/store.js index b93ba170ad..01e6cd009e 100644 --- a/app/javascript/vue/tasks/new_matrix/store/store.js +++ b/app/javascript/vue/tasks/new_matrix/store/store.js @@ -9,12 +9,21 @@ Vue.use(Vuex) function makeInitialState () { return { + settings: { + loadingRows: false, + loadingColumns: false + }, + configParams: { + per: 500 + }, matrix: { id: undefined, name: undefined, project_id: undefined, global_id: undefined }, + columnFixedPagination: undefined, + rowFixedPagination: undefined, matrixView: 'row', matrixMode: 'fixed', matrixRowItems: [], diff --git a/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/citationPages.vue b/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/citationPages.vue index f613272eb8..a965e12762 100644 --- a/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/citationPages.vue +++ b/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/citationPages.vue @@ -30,7 +30,7 @@ export default { id: item.id, origin_citation_attributes: { id: (item.hasOwnProperty('origin_citation') ? item.origin_citation.id : null), - source_id: (item.hasOwnProperty('origin_citation') ? item.origin_citation.source_id : null), + source_id: (item.hasOwnProperty('origin_citation') ? item.origin_citation.source.id : null), pages: value } } diff --git a/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/sourcePicker.vue b/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/sourcePicker.vue index efee53d6c8..1d62ff92e7 100644 --- a/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/sourcePicker.vue +++ b/app/javascript/vue/tasks/nomenclature/new_taxon_name/components/sourcePicker.vue @@ -73,7 +73,7 @@ -
+
-
+

@@ -128,7 +128,7 @@
-
+
{ -// commit(MutationNames.SetCitation, response) -// }) } diff --git a/app/javascript/vue/tasks/nomenclature/new_taxon_name/store/actions/updateSource.js b/app/javascript/vue/tasks/nomenclature/new_taxon_name/store/actions/updateSource.js new file mode 100644 index 0000000000..56a0403cb1 --- /dev/null +++ b/app/javascript/vue/tasks/nomenclature/new_taxon_name/store/actions/updateSource.js @@ -0,0 +1,24 @@ +import { updateTaxonName } from '../../request/resources' +import { MutationNames } from '../mutations/mutations' + +export default function ({ commit, state, dispatch }, citation) { + return new Promise(function (resolve, reject) { + + const taxonName = { + id: state.taxon_name.id, + origin_citation_attributes: { + id: citation.id, + source_id: citation.source_id, + pages: citation.pages + } + } + + updateTaxonName(taxonName).then(response => { + dispatch('loadSoftValidation', 'taxon_name') + commit(MutationNames.UpdateLastSave) + return resolve(response) + }, response => { + return reject(response) + }) + }) +} \ No newline at end of file diff --git a/app/models/biological_relationship.rb b/app/models/biological_relationship.rb index 428d602f48..e34310bbe3 100644 --- a/app/models/biological_relationship.rb +++ b/app/models/biological_relationship.rb @@ -71,7 +71,8 @@ def self.select_optimized(user_id, project_id) pinboard: BiologicalRelationship.pinned_by(user_id).where(project_id: project_id).to_a } - h[:quick] = (BiologicalRelationship.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (BiologicalRelationship.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + + BiologicalRelationship.joins(:biological_associations).used_recently(user_id, project_id).distinct.limit(4).order(:name).to_a).uniq h end end diff --git a/app/models/collecting_event.rb b/app/models/collecting_event.rb index 97f0964c73..201a99ab04 100644 --- a/app/models/collecting_event.rb +++ b/app/models/collecting_event.rb @@ -325,7 +325,8 @@ def select_optimized(user_id, project_id) pinboard: CollectingEvent.pinned_by(user_id).pinned_in_project(project_id).to_a } - h[:quick] = (CollectingEvent.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (CollectingEvent.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + + h[:recent]).uniq h end diff --git a/app/models/confidence_level.rb b/app/models/confidence_level.rb index 36290d63f5..040e589937 100644 --- a/app/models/confidence_level.rb +++ b/app/models/confidence_level.rb @@ -40,7 +40,8 @@ def self.select_optimized(user_id, project_id, klass) pinboard: ConfidenceLevel.pinned_by(user_id).where(project_id: project_id).to_a } - h[:quick] = (ConfidenceLevel.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (ConfidenceLevel.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + + ConfidenceLevel.used_on_klass(klass).used_recently(user_id, project_id).distinct.limit(4).order(:name).to_a).uniq h end diff --git a/app/models/geographic_area.rb b/app/models/geographic_area.rb index e301901574..b77cfb3f40 100644 --- a/app/models/geographic_area.rb +++ b/app/models/geographic_area.rb @@ -462,8 +462,18 @@ def self.select_optimized(user_id, project_id, target = 'CollectingEvent') h[:recent] ||= [] - # TODO: stupid, loop the array from above - h[:quick] = (GeographicArea.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + h[:recent][0..3]).uniq + h[:quick] = GeographicArea.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + case target + when 'CollectingEvent' + h[:quick] = (h[:quick] + GeographicArea.joins(:collecting_events).where(collecting_events: {project_id: project_id, updated_by_id: user_id}). + used_recently(user_id, project_id, 'CollectingEvent'). + distinct.limit(4).order(:name).to_a).uniq + when 'AssertedDistribution' + h[:quick] = (h[:quick] + GeographicArea.joins(:asserted_distributions). + where(asserted_distributions: {project_id: project_id, updated_by_id: user_id}). + used_recently(user_id, project_id, 'AssertedDistribution'). + distinct.limit(4).order(:name).to_a).uniq + end h end diff --git a/app/models/keyword.rb b/app/models/keyword.rb index 065eb9d1df..4758124df5 100644 --- a/app/models/keyword.rb +++ b/app/models/keyword.rb @@ -40,14 +40,12 @@ def self.select_optimized(user_id, project_id, klass) h = { recent: ( Keyword.where(project_id: project_id, created_by_id: user_id, created_at: 1.day.ago..Time.now) - .limit(5) - .order(:name).to_a + + .limit(5).to_a + Keyword.joins(:tags) .where(project_id: project_id, tags: {updated_by_id: user_id}) .used_on_klass(klass) .used_recently(user_id, project_id) - .distinct.limit(5) - .order(:name).to_a ).uniq, + .distinct.limit(5).to_a ).uniq, pinboard: Keyword.pinned_by(user_id).where(project_id: project_id).to_a } diff --git a/app/models/language.rb b/app/models/language.rb index bbdeef36bd..aba3b25847 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -53,16 +53,16 @@ def self.find_for_autocomplete(params) # @param klass ['source' || 'serial'] def self.select_optimized(user_id, project_id, klass = 'source') recent = if klass == 'source' - Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).distinct.limit(10).to_a.sort{|a,b| a.english_name <=> b.english_name} + Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).distinct.limit(10) elsif klass == 'serial' - Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).distinct.limit(10).to_a.sort{|a,b| a.english_name <=> b.english_name} + Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).distinct.limit(10).to_a end h = { recent: recent, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a } - h[:quick] = (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent].sort_by{|a| -a.created_at}[0..3]).uniq h end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 9aa16286d3..f1336c7481 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -66,7 +66,7 @@ def self.select_optimized(user_id, project_id, klass) .where(identifiers: {updated_by_id: user_id}) .used_in_project(project_id) .used_recently - .distinct.limit(6).order(:name).to_a + + .distinct.limit(6).to_a + Namespace.where(created_by_id: user_id, created_at: (3.hours.ago..Time.now)).limit(5)).uniq, pinboard: Namespace.pinned_by(user_id).pinned_in_project(project_id).to_a } diff --git a/app/models/otu.rb b/app/models/otu.rb index 14c3b5f581..35eca76d77 100644 --- a/app/models/otu.rb +++ b/app/models/otu.rb @@ -328,13 +328,13 @@ def self.select_optimized(user_id, project_id, target = nil) .limit(10).to_a + Otu.where(project_id: project_id, created_by_id: user_id, created_at: 3.hours.ago..Time.now) .order('updated_at DESC') - .limit(3).order(:name).to_a + .limit(3).to_a ).uniq.sort{|a,b| a.otu_name <=> b.otu_name} else - h[:recent] = Otu.where(project_id: project_id).order('updated_at DESC').limit(10).to_a.sort{|a,b| a.otu_name <=> b.otu_name} + h[:recent] = Otu.where(project_id: project_id).order('updated_at DESC').limit(10) end - h[:quick] = (Otu.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (Otu.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq h end diff --git a/app/models/person.rb b/app/models/person.rb index 4c2d655c92..9036bcfa33 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -469,10 +469,11 @@ def self.select_optimized(user_id, project_id, role_type = 'SourceAuthor') end h[:recent] = - (Person.joins(:roles).where(roles: role_params).used_recently(role_type).distinct.limit(10).order(:cached).to_a + - Person.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).order('created_at DESC').limit(6).order(:cached).to_a).uniq + (Person.joins(:roles).where(roles: role_params).used_recently(role_type).distinct.limit(10).to_a + + Person.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).order('created_at DESC').limit(6).to_a).uniq - h[:quick] = (Person.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + h[:recent][0..3]).uniq + h[:quick] = (Person.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + + h[:recent][0..3]).uniq h end diff --git a/app/models/predicate.rb b/app/models/predicate.rb index 401808859f..10f7a117f5 100644 --- a/app/models/predicate.rb +++ b/app/models/predicate.rb @@ -31,7 +31,7 @@ def self.select_optimized(user_id, project_id, klass) h = {recent: (Predicate.joins(:internal_attributes).used_on_klass(klass) .used_recently(user_id, project_id) .where(project_id: project_id, data_attributes: {created_by_id: user_id}) - .distinct.limit(10).order(:name).to_a + + .distinct.limit(10).to_a + Predicate.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).order(:name).to_a).uniq, pinboard: Predicate.pinned_by(user_id).where(project_id: project_id).to_a } diff --git a/app/models/repository.rb b/app/models/repository.rb index 95c3878a67..ab9891ea51 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -56,7 +56,8 @@ def self.select_optimized(user_id, project_id) pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a } - h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + + Repository.used_in_project(project_id).where(collection_objects: {created_by_id: user_id}).used_recently.distinct.limit(3).order(:name).to_a).uniq h end diff --git a/app/models/sequence.rb b/app/models/sequence.rb index 6655836d5e..2bd443f6a2 100644 --- a/app/models/sequence.rb +++ b/app/models/sequence.rb @@ -137,7 +137,7 @@ def self.select_optimized(user_id, project_id, target = nil) a = target.tableize.to_sym h[:recent] = ( b.limit(3).to_a + - Sequence.joins(a).where(project_id: project_id, a => {created_by_id: user_id}).used_recently(user_id, project_id, target).limit(10).order(:name).to_a + Sequence.joins(a).where(project_id: project_id, a => {created_by_id: user_id}).used_recently(user_id, project_id, target).limit(10).to_a ).uniq else h[:recent] = b.limit(10).to_a diff --git a/app/models/serial.rb b/app/models/serial.rb index f1ae92ba56..7c46459c72 100644 --- a/app/models/serial.rb +++ b/app/models/serial.rb @@ -163,7 +163,7 @@ def self.select_optimized(user_id, project_id) pinboard: Serial.pinned_by(user_id).pinned_in_project(project_id).to_a } - h[:quick] = (Serial.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent][0..3]).uniq + h[:quick] = (Serial.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + h[:recent]).uniq h end diff --git a/app/models/source.rb b/app/models/source.rb index 04671ab45f..4da5b06ce4 100644 --- a/app/models/source.rb +++ b/app/models/source.rb @@ -322,7 +322,7 @@ def self.select_optimized(user_id, project_id, target = 'TaxonName') h[:recent] ||= [] - h[:quick] = ( Source.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + h[:recent][0..3]).uniq + h[:quick] = ( Source.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id: project_id}).to_a + h[:recent]).uniq h end diff --git a/app/models/topic.rb b/app/models/topic.rb index 1ea22682ba..b4c45dce73 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -86,7 +86,7 @@ def self.select_optimized(user_id, project_id, klass, target = 'Citation') end h[:quick] = (Topic.pinned_by(user_id) - .pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq + .pinboard_inserted.where(project_id: project_id).to_a + h[:recent]).uniq h end diff --git a/spec/models/observation_matrix_spec.rb b/spec/models/observation_matrix_spec.rb index a329d94162..cb724f3b93 100644 --- a/spec/models/observation_matrix_spec.rb +++ b/spec/models/observation_matrix_spec.rb @@ -42,11 +42,40 @@ end specify 'cascade creates columns from items 1' do - observation_matrix.observation_matrix_column_items << ObservationMatrixColumnItem::SingleDescriptor.new(descriptor: descriptor) + observation_matrix.observation_matrix_column_items << ObservationMatrixColumnItem::SingleDescriptor.new(descriptor: descriptor) expect(observation_matrix.observation_matrix_columns.count).to eq(1) end - end + context 'deletable' do + specify 'delete matrix' do + om = ObservationMatrix.create(name: 'test') + descriptor1 = Descriptor::Continuous.create!(name: 'working') + + r1 = ObservationMatrixRowItem::SingleOtu.create(otu: otu, observation_matrix: om) + r2 = ObservationMatrixRowItem::SingleCollectionObject.create(collection_object: collection_object, observation_matrix: om) + c3 = ObservationMatrixColumnItem::SingleDescriptor.create(descriptor: descriptor, observation_matrix: om) + o1 = Observation.create(otu: otu, descriptor: descriptor1, continuous_value: 6) + o2 = Observation.create(collection_object: collection_object, descriptor: descriptor1, continuous_value: 5) + om.reload + + expect(ObservationMatrix.where(id: om.id).first.nil?).to be_falsey + expect(ObservationMatrixRowItem.where(id: r1.id).first.nil?).to be_falsey + expect(ObservationMatrixRowItem.where(id: r2.id).first.nil?).to be_falsey + expect(ObservationMatrixColumnItem.where(id: c3.id).first.nil?).to be_falsey + + expect(om.destroy!).to be_truthy + expect(ObservationMatrix.where(id: om.id).first.nil?).to be_truthy + expect(ObservationMatrixRowItem.where(id: r1.id).first.nil?).to be_truthy + expect(ObservationMatrixRowItem.where(id: r2.id).first.nil?).to be_truthy + expect(ObservationMatrixColumnItem.where(id: c3.id).first.nil?).to be_truthy + expect(Otu.where(id: otu.id).first.nil?).to be_falsey + expect(CollectionObject.where(id: collection_object.id).first.nil?).to be_falsey + expect(Descriptor.where(id: descriptor1.id).first.nil?).to be_falsey + expect(Observation.where(id: o1.id).first.nil?).to be_falsey + expect(Observation.where(id: o2.id).first.nil?).to be_falsey + end + end + end end