{
-// 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