From 80c1eda2e8b073f7b70013fdc26918b65266192f Mon Sep 17 00:00:00 2001 From: rhigman <73792779+rhigman@users.noreply.github.com> Date: Tue, 2 Nov 2021 09:54:42 +0000 Subject: [PATCH 01/23] Rename all instances of funder to institution --- thoth-api/migrations/0.4.8/down.sql | 12 + thoth-api/migrations/0.4.8/up.sql | 12 + thoth-api/src/graphql/model.rs | 70 ++--- thoth-api/src/model/funder/mod.rs | 151 ---------- thoth-api/src/model/funding/crud.rs | 10 +- thoth-api/src/model/funding/mod.rs | 16 +- .../src/model/{funder => institution}/crud.rs | 96 +++--- thoth-api/src/model/institution/mod.rs | 161 ++++++++++ thoth-api/src/model/mod.rs | 2 +- thoth-api/src/model/work/mod.rs | 4 +- thoth-api/src/schema.rs | 26 +- ...ker.rs => institution_activity_checker.rs} | 50 ++-- thoth-app/src/agent/mod.rs | 2 +- thoth-app/src/component/admin.rs | 12 +- thoth-app/src/component/funders.rs | 30 -- thoth-app/src/component/fundings_form.rs | 104 +++---- .../component/{funder.rs => institution.rs} | 280 +++++++++--------- thoth-app/src/component/institutions.rs | 30 ++ thoth-app/src/component/menu.rs | 6 +- thoth-app/src/component/mod.rs | 6 +- .../{new_funder.rs => new_institution.rs} | 124 ++++---- thoth-app/src/component/work.rs | 4 +- .../models/funder/create_funder_mutation.rs | 45 --- .../models/funder/delete_funder_mutation.rs | 42 --- thoth-app/src/models/funder/funder_query.rs | 38 --- thoth-app/src/models/funder/funders_query.rs | 46 --- thoth-app/src/models/funder/mod.rs | 51 ---- .../models/funder/update_funder_mutation.rs | 49 --- .../models/funding/create_funding_mutation.rs | 18 +- .../models/funding/delete_funding_mutation.rs | 2 +- .../create_institution_mutation.rs | 45 +++ .../delete_institution_mutation.rs | 42 +++ .../institution_activity_query.rs} | 28 +- .../models/institution/institution_query.rs | 38 +++ .../models/institution/institutions_query.rs | 46 +++ thoth-app/src/models/institution/mod.rs | 51 ++++ .../update_institution_mutation.rs | 49 +++ thoth-app/src/models/mod.rs | 2 +- thoth-app/src/models/work/work_query.rs | 8 +- thoth-app/src/route.rs | 12 +- thoth-app/src/string.rs | 4 +- thoth-client/assets/queries.graphql | 6 +- thoth-client/assets/schema.json | 98 +++--- thoth-export-server/src/csv/csv_thoth.rs | 36 ++- thoth-export-server/src/xml/onix3_jstor.rs | 8 +- thoth-export-server/src/xml/onix3_oapen.rs | 18 +- .../src/xml/onix3_project_muse.rs | 8 +- 47 files changed, 1022 insertions(+), 976 deletions(-) create mode 100644 thoth-api/migrations/0.4.8/down.sql create mode 100644 thoth-api/migrations/0.4.8/up.sql delete mode 100644 thoth-api/src/model/funder/mod.rs rename thoth-api/src/model/{funder => institution}/crud.rs (52%) create mode 100644 thoth-api/src/model/institution/mod.rs rename thoth-app/src/agent/{funder_activity_checker.rs => institution_activity_checker.rs} (56%) delete mode 100644 thoth-app/src/component/funders.rs rename thoth-app/src/component/{funder.rs => institution.rs} (55%) create mode 100644 thoth-app/src/component/institutions.rs rename thoth-app/src/component/{new_funder.rs => new_institution.rs} (59%) delete mode 100644 thoth-app/src/models/funder/create_funder_mutation.rs delete mode 100644 thoth-app/src/models/funder/delete_funder_mutation.rs delete mode 100644 thoth-app/src/models/funder/funder_query.rs delete mode 100644 thoth-app/src/models/funder/funders_query.rs delete mode 100644 thoth-app/src/models/funder/mod.rs delete mode 100644 thoth-app/src/models/funder/update_funder_mutation.rs create mode 100644 thoth-app/src/models/institution/create_institution_mutation.rs create mode 100644 thoth-app/src/models/institution/delete_institution_mutation.rs rename thoth-app/src/models/{funder/funder_activity_query.rs => institution/institution_activity_query.rs} (68%) create mode 100644 thoth-app/src/models/institution/institution_query.rs create mode 100644 thoth-app/src/models/institution/institutions_query.rs create mode 100644 thoth-app/src/models/institution/mod.rs create mode 100644 thoth-app/src/models/institution/update_institution_mutation.rs diff --git a/thoth-api/migrations/0.4.8/down.sql b/thoth-api/migrations/0.4.8/down.sql new file mode 100644 index 00000000..d4458f8b --- /dev/null +++ b/thoth-api/migrations/0.4.8/down.sql @@ -0,0 +1,12 @@ +ALTER TABLE institution_history RENAME COLUMN institution_history_id TO funder_history_id; +ALTER TABLE institution_history RENAME COLUMN institution_id TO funder_id; + +ALTER TABLE institution_history RENAME TO funder_history; + +ALTER TABLE institution RENAME COLUMN institution_id TO funder_id; +ALTER TABLE institution RENAME COLUMN institution_name TO funder_name; +ALTER TABLE institution RENAME COLUMN institution_doi TO funder_doi; + +ALTER TABLE institution RENAME TO funder; + +ALTER TABLE funding RENAME COLUMN institution_id TO funder_id; diff --git a/thoth-api/migrations/0.4.8/up.sql b/thoth-api/migrations/0.4.8/up.sql new file mode 100644 index 00000000..3832d6e2 --- /dev/null +++ b/thoth-api/migrations/0.4.8/up.sql @@ -0,0 +1,12 @@ +ALTER TABLE funder RENAME TO institution; + +ALTER TABLE institution RENAME COLUMN funder_id TO institution_id; +ALTER TABLE institution RENAME COLUMN funder_name TO institution_name; +ALTER TABLE institution RENAME COLUMN funder_doi TO institution_doi; + +ALTER TABLE funder_history RENAME TO institution_history; + +ALTER TABLE institution_history RENAME COLUMN funder_history_id TO institution_history_id; +ALTER TABLE institution_history RENAME COLUMN funder_id TO institution_id; + +ALTER TABLE funding RENAME COLUMN funder_id TO institution_id; diff --git a/thoth-api/src/graphql/model.rs b/thoth-api/src/graphql/model.rs index 4a1d1083..4c0c536e 100644 --- a/thoth-api/src/graphql/model.rs +++ b/thoth-api/src/graphql/model.rs @@ -9,9 +9,9 @@ use crate::account::model::DecodedToken; use crate::db::PgPool; use crate::model::contribution::*; use crate::model::contributor::*; -use crate::model::funder::*; use crate::model::funding::*; use crate::model::imprint::*; +use crate::model::institution::*; use crate::model::issue::*; use crate::model::language::*; use crate::model::price::*; @@ -834,28 +834,28 @@ impl QueryRoot { } #[graphql( - description = "Query the full list of funders", + description = "Query the full list of institutions", arguments( limit(default = 100, description = "The number of items to return"), offset(default = 0, description = "The number of items to skip"), filter( default = "".to_string(), - description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on funderName and funderDoi", + description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on institutionName and institutionDoi", ), order( - default = FunderOrderBy::default(), + default = InstitutionOrderBy::default(), description = "The order in which to sort the results", ), ) )] - fn funders( + fn institutions( context: &Context, limit: i32, offset: i32, filter: String, - order: FunderOrderBy, - ) -> FieldResult> { - Funder::all( + order: InstitutionOrderBy, + ) -> FieldResult> { + Institution::all( &context.db, limit, offset, @@ -870,22 +870,22 @@ impl QueryRoot { .map_err(|e| e.into()) } - #[graphql(description = "Query a single funder using its id")] - fn funder(context: &Context, funder_id: Uuid) -> FieldResult { - Funder::from_id(&context.db, &funder_id).map_err(|e| e.into()) + #[graphql(description = "Query a single institution using its id")] + fn institution(context: &Context, institution_id: Uuid) -> FieldResult { + Institution::from_id(&context.db, &institution_id).map_err(|e| e.into()) } #[graphql( - description = "Get the total number of funders", + description = "Get the total number of institutions", arguments( filter( default = "".to_string(), - description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on funderName and funderDoi", + description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on institutionName and institutionDoi", ), ) )] - fn funder_count(context: &Context, filter: String) -> FieldResult { - Funder::count(&context.db, Some(filter), vec![], None, None).map_err(|e| e.into()) + fn institution_count(context: &Context, filter: String) -> FieldResult { + Institution::count(&context.db, Some(filter), vec![], None, None).map_err(|e| e.into()) } #[graphql( @@ -1023,9 +1023,9 @@ impl MutationRoot { Language::create(&context.db, &data).map_err(|e| e.into()) } - fn create_funder(context: &Context, data: NewFunder) -> FieldResult { + fn create_institution(context: &Context, data: NewInstitution) -> FieldResult { context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?; - Funder::create(&context.db, &data).map_err(|e| e.into()) + Institution::create(&context.db, &data).map_err(|e| e.into()) } fn create_funding(context: &Context, data: NewFunding) -> FieldResult { @@ -1213,10 +1213,10 @@ impl MutationRoot { .map_err(|e| e.into()) } - fn update_funder(context: &Context, data: PatchFunder) -> FieldResult { + fn update_institution(context: &Context, data: PatchInstitution) -> FieldResult { context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?; let account_id = context.token.jwt.as_ref().unwrap().account_id(&context.db); - Funder::from_id(&context.db, &data.funder_id) + Institution::from_id(&context.db, &data.institution_id) .unwrap() .update(&context.db, &data, &account_id) .map_err(|e| e.into()) @@ -1370,9 +1370,9 @@ impl MutationRoot { language.delete(&context.db).map_err(|e| e.into()) } - fn delete_funder(context: &Context, funder_id: Uuid) -> FieldResult { + fn delete_institution(context: &Context, institution_id: Uuid) -> FieldResult { context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?; - Funder::from_id(&context.db, &funder_id) + Institution::from_id(&context.db, &institution_id) .unwrap() .delete(&context.db) .map_err(|e| e.into()) @@ -2407,17 +2407,17 @@ impl Subject { } #[juniper::object(Context = Context, description = "An organisation that provides the money to pay for the publication of a work.")] -impl Funder { - pub fn funder_id(&self) -> &Uuid { - &self.funder_id +impl Institution { + pub fn institution_id(&self) -> &Uuid { + &self.institution_id } - pub fn funder_name(&self) -> &String { - &self.funder_name + pub fn institution_name(&self) -> &String { + &self.institution_name } - pub fn funder_doi(&self) -> Option<&Doi> { - self.funder_doi.as_ref() + pub fn institution_doi(&self) -> Option<&Doi> { + self.institution_doi.as_ref() } pub fn created_at(&self) -> Timestamp { @@ -2429,7 +2429,7 @@ impl Funder { } #[graphql( - description = "Get fundings linked to this funder", + description = "Get fundings linked to this institution", arguments( limit(default = 100, description = "The number of items to return"), offset(default = 0, description = "The number of items to skip"), @@ -2459,7 +2459,7 @@ impl Funder { order, vec![], None, - Some(self.funder_id), + Some(self.institution_id), None, None, ) @@ -2467,7 +2467,7 @@ impl Funder { } } -#[juniper::object(Context = Context, description = "A grant awarded to the publication of a work by a funder.")] +#[juniper::object(Context = Context, description = "A grant awarded to the publication of a work by an institution.")] impl Funding { pub fn funding_id(&self) -> &Uuid { &self.funding_id @@ -2477,8 +2477,8 @@ impl Funding { &self.work_id } - pub fn funder_id(&self) -> &Uuid { - &self.funder_id + pub fn institution_id(&self) -> &Uuid { + &self.institution_id } pub fn program(&self) -> Option<&String> { @@ -2513,8 +2513,8 @@ impl Funding { Work::from_id(&context.db, &self.work_id).map_err(|e| e.into()) } - pub fn funder(&self, context: &Context) -> FieldResult { - Funder::from_id(&context.db, &self.funder_id).map_err(|e| e.into()) + pub fn institution(&self, context: &Context) -> FieldResult { + Institution::from_id(&context.db, &self.institution_id).map_err(|e| e.into()) } } diff --git a/thoth-api/src/model/funder/mod.rs b/thoth-api/src/model/funder/mod.rs deleted file mode 100644 index ca0dad44..00000000 --- a/thoth-api/src/model/funder/mod.rs +++ /dev/null @@ -1,151 +0,0 @@ -use serde::Deserialize; -use serde::Serialize; -use std::fmt; -use strum::Display; -use strum::EnumString; -use uuid::Uuid; - -use crate::graphql::utils::Direction; -use crate::model::Doi; -use crate::model::Timestamp; -#[cfg(feature = "backend")] -use crate::schema::funder; -#[cfg(feature = "backend")] -use crate::schema::funder_history; - -#[cfg_attr( - feature = "backend", - derive(juniper::GraphQLEnum), - graphql(description = "Field to use when sorting funders list") -)] -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, EnumString, Display)] -#[serde(rename_all = "SCREAMING_SNAKE_CASE")] -pub enum FunderField { - #[strum(serialize = "ID")] - FunderId, - #[strum(serialize = "Funder")] - FunderName, - #[strum(serialize = "DOI")] - FunderDoi, - CreatedAt, - UpdatedAt, -} - -#[cfg_attr(feature = "backend", derive(Queryable))] -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "camelCase")] -pub struct Funder { - pub funder_id: Uuid, - pub funder_name: String, - pub funder_doi: Option, - pub created_at: Timestamp, - pub updated_at: Timestamp, -} - -#[cfg_attr( - feature = "backend", - derive(juniper::GraphQLInputObject, Insertable), - table_name = "funder" -)] -pub struct NewFunder { - pub funder_name: String, - pub funder_doi: Option, -} - -#[cfg_attr( - feature = "backend", - derive(juniper::GraphQLInputObject, AsChangeset), - changeset_options(treat_none_as_null = "true"), - table_name = "funder" -)] -pub struct PatchFunder { - pub funder_id: Uuid, - pub funder_name: String, - pub funder_doi: Option, -} - -#[cfg_attr(feature = "backend", derive(Queryable))] -pub struct FunderHistory { - pub funder_history_id: Uuid, - pub funder_id: Uuid, - pub account_id: Uuid, - pub data: serde_json::Value, - pub timestamp: Timestamp, -} - -#[cfg_attr(feature = "backend", derive(Insertable), table_name = "funder_history")] -pub struct NewFunderHistory { - pub funder_id: Uuid, - pub account_id: Uuid, - pub data: serde_json::Value, -} - -#[cfg_attr( - feature = "backend", - derive(juniper::GraphQLInputObject), - graphql(description = "Field and order to use when sorting funders list") -)] -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] -pub struct FunderOrderBy { - pub field: FunderField, - pub direction: Direction, -} - -impl Default for FunderField { - fn default() -> Self { - FunderField::FunderName - } -} - -impl fmt::Display for Funder { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if let Some(doi) = &self.funder_doi { - write!(f, "{} - {}", &self.funder_name, doi) - } else { - write!(f, "{}", &self.funder_name) - } - } -} - -#[test] -fn test_funderfield_default() { - let fundfield: FunderField = Default::default(); - assert_eq!(fundfield, FunderField::FunderName); -} - -#[test] -fn test_funderfield_display() { - assert_eq!(format!("{}", FunderField::FunderId), "ID"); - assert_eq!(format!("{}", FunderField::FunderName), "Funder"); - assert_eq!(format!("{}", FunderField::FunderDoi), "DOI"); - assert_eq!(format!("{}", FunderField::CreatedAt), "CreatedAt"); - assert_eq!(format!("{}", FunderField::UpdatedAt), "UpdatedAt"); -} - -#[test] -fn test_funderfield_fromstr() { - use std::str::FromStr; - assert_eq!(FunderField::from_str("ID").unwrap(), FunderField::FunderId); - assert_eq!( - FunderField::from_str("Funder").unwrap(), - FunderField::FunderName - ); - assert_eq!( - FunderField::from_str("DOI").unwrap(), - FunderField::FunderDoi - ); - assert_eq!( - FunderField::from_str("CreatedAt").unwrap(), - FunderField::CreatedAt - ); - assert_eq!( - FunderField::from_str("UpdatedAt").unwrap(), - FunderField::UpdatedAt - ); - assert!(FunderField::from_str("FunderID").is_err()); - assert!(FunderField::from_str("Website").is_err()); - assert!(FunderField::from_str("Fundings").is_err()); -} - -#[cfg(feature = "backend")] -pub mod crud; diff --git a/thoth-api/src/model/funding/crud.rs b/thoth-api/src/model/funding/crud.rs index f4a9d4e2..144a35d7 100644 --- a/thoth-api/src/model/funding/crud.rs +++ b/thoth-api/src/model/funding/crud.rs @@ -38,7 +38,7 @@ impl Crud for Funding { .select(( funding_id, work_id, - funder_id, + institution_id, program, project_name, project_shortname, @@ -58,9 +58,9 @@ impl Crud for Funding { Direction::Asc => query = query.order(work_id.asc()), Direction::Desc => query = query.order(work_id.desc()), }, - FundingField::FunderId => match order.direction { - Direction::Asc => query = query.order(funder_id.asc()), - Direction::Desc => query = query.order(funder_id.desc()), + FundingField::InstitutionId => match order.direction { + Direction::Asc => query = query.order(institution_id.asc()), + Direction::Desc => query = query.order(institution_id.desc()), }, FundingField::Program => match order.direction { Direction::Asc => query = query.order(program.asc()), @@ -101,7 +101,7 @@ impl Crud for Funding { query = query.filter(work_id.eq(pid)); } if let Some(pid) = parent_id_2 { - query = query.filter(funder_id.eq(pid)); + query = query.filter(institution_id.eq(pid)); } match query .limit(limit.into()) diff --git a/thoth-api/src/model/funding/mod.rs b/thoth-api/src/model/funding/mod.rs index dab2f5ef..cf0e8409 100644 --- a/thoth-api/src/model/funding/mod.rs +++ b/thoth-api/src/model/funding/mod.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::model::funder::Funder; +use crate::model::institution::Institution; use crate::model::work::WorkWithRelations; use crate::model::Timestamp; #[cfg(feature = "backend")] @@ -15,7 +15,7 @@ use crate::schema::funding_history; graphql(description = "Field to use when sorting fundings list") )] pub enum FundingField { - FunderId, + InstitutionId, WorkId, FundingId, Program, @@ -33,7 +33,7 @@ pub enum FundingField { pub struct Funding { pub funding_id: Uuid, pub work_id: Uuid, - pub funder_id: Uuid, + pub institution_id: Uuid, pub program: Option, pub project_name: Option, pub project_shortname: Option, @@ -45,16 +45,16 @@ pub struct Funding { #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] -pub struct FundingWithFunder { +pub struct FundingWithInstitution { pub funding_id: Uuid, pub work_id: Uuid, - pub funder_id: Uuid, + pub institution_id: Uuid, pub program: Option, pub project_name: Option, pub project_shortname: Option, pub grant_number: Option, pub jurisdiction: Option, - pub funder: Funder, + pub institution: Institution, } #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] @@ -70,7 +70,7 @@ pub struct FundingWithWork { )] pub struct NewFunding { pub work_id: Uuid, - pub funder_id: Uuid, + pub institution_id: Uuid, pub program: Option, pub project_name: Option, pub project_shortname: Option, @@ -87,7 +87,7 @@ pub struct NewFunding { pub struct PatchFunding { pub funding_id: Uuid, pub work_id: Uuid, - pub funder_id: Uuid, + pub institution_id: Uuid, pub program: Option, pub project_name: Option, pub project_shortname: Option, diff --git a/thoth-api/src/model/funder/crud.rs b/thoth-api/src/model/institution/crud.rs similarity index 52% rename from thoth-api/src/model/funder/crud.rs rename to thoth-api/src/model/institution/crud.rs index a6fbe085..1cde4251 100644 --- a/thoth-api/src/model/funder/crud.rs +++ b/thoth-api/src/model/institution/crud.rs @@ -1,9 +1,10 @@ use super::{ - Funder, FunderField, FunderHistory, FunderOrderBy, NewFunder, NewFunderHistory, PatchFunder, + Institution, InstitutionField, InstitutionHistory, InstitutionOrderBy, NewInstitution, + NewInstitutionHistory, PatchInstitution, }; use crate::graphql::utils::Direction; use crate::model::{Crud, DbInsert, HistoryEntry}; -use crate::schema::{funder, funder_history}; +use crate::schema::{institution, institution_history}; use crate::{crud_methods, db_insert}; use diesel::{ BoolExpressionMethods, ExpressionMethods, PgTextExpressionMethods, QueryDsl, RunQueryDsl, @@ -11,15 +12,15 @@ use diesel::{ use thoth_errors::{ThothError, ThothResult}; use uuid::Uuid; -impl Crud for Funder { - type NewEntity = NewFunder; - type PatchEntity = PatchFunder; - type OrderByEntity = FunderOrderBy; +impl Crud for Institution { + type NewEntity = NewInstitution; + type PatchEntity = PatchInstitution; + type OrderByEntity = InstitutionOrderBy; type FilterParameter1 = (); type FilterParameter2 = (); fn pk(&self) -> Uuid { - self.funder_id + self.institution_id } fn all( @@ -33,44 +34,44 @@ impl Crud for Funder { _: Option, _: Option, _: Option, - ) -> ThothResult> { - use crate::schema::funder::dsl::*; + ) -> ThothResult> { + use crate::schema::institution::dsl::*; let connection = db.get().unwrap(); - let mut query = funder.into_boxed(); + let mut query = institution.into_boxed(); match order.field { - FunderField::FunderId => match order.direction { - Direction::Asc => query = query.order(funder_id.asc()), - Direction::Desc => query = query.order(funder_id.desc()), + InstitutionField::InstitutionId => match order.direction { + Direction::Asc => query = query.order(institution_id.asc()), + Direction::Desc => query = query.order(institution_id.desc()), }, - FunderField::FunderName => match order.direction { - Direction::Asc => query = query.order(funder_name.asc()), - Direction::Desc => query = query.order(funder_name.desc()), + InstitutionField::InstitutionName => match order.direction { + Direction::Asc => query = query.order(institution_name.asc()), + Direction::Desc => query = query.order(institution_name.desc()), }, - FunderField::FunderDoi => match order.direction { - Direction::Asc => query = query.order(funder_doi.asc()), - Direction::Desc => query = query.order(funder_doi.desc()), + InstitutionField::InstitutionDoi => match order.direction { + Direction::Asc => query = query.order(institution_doi.asc()), + Direction::Desc => query = query.order(institution_doi.desc()), }, - FunderField::CreatedAt => match order.direction { + InstitutionField::CreatedAt => match order.direction { Direction::Asc => query = query.order(created_at.asc()), Direction::Desc => query = query.order(created_at.desc()), }, - FunderField::UpdatedAt => match order.direction { + InstitutionField::UpdatedAt => match order.direction { Direction::Asc => query = query.order(updated_at.asc()), Direction::Desc => query = query.order(updated_at.desc()), }, } if let Some(filter) = filter { query = query.filter( - funder_name + institution_name .ilike(format!("%{}%", filter)) - .or(funder_doi.ilike(format!("%{}%", filter))), + .or(institution_doi.ilike(format!("%{}%", filter))), ); } match query .limit(limit.into()) .offset(offset.into()) - .load::(&connection) + .load::(&connection) { Ok(t) => Ok(t), Err(e) => Err(ThothError::from(e)), @@ -84,14 +85,14 @@ impl Crud for Funder { _: Option, _: Option, ) -> ThothResult { - use crate::schema::funder::dsl::*; + use crate::schema::institution::dsl::*; let connection = db.get().unwrap(); - let mut query = funder.into_boxed(); + let mut query = institution.into_boxed(); if let Some(filter) = filter { query = query.filter( - funder_name + institution_name .ilike(format!("%{}%", filter)) - .or(funder_doi.ilike(format!("%{}%", filter))), + .or(institution_doi.ilike(format!("%{}%", filter))), ); } @@ -107,29 +108,29 @@ impl Crud for Funder { fn publisher_id(&self, _db: &crate::db::PgPool) -> ThothResult { Err(ThothError::InternalError( - "Method publisher_id() is not supported for Funder objects".to_string(), + "Method publisher_id() is not supported for Institution objects".to_string(), )) } - crud_methods!(funder::table, funder::dsl::funder); + crud_methods!(institution::table, institution::dsl::institution); } -impl HistoryEntry for Funder { - type NewHistoryEntity = NewFunderHistory; +impl HistoryEntry for Institution { + type NewHistoryEntity = NewInstitutionHistory; fn new_history_entry(&self, account_id: &Uuid) -> Self::NewHistoryEntity { Self::NewHistoryEntity { - funder_id: self.funder_id, + institution_id: self.institution_id, account_id: *account_id, data: serde_json::Value::String(serde_json::to_string(&self).unwrap()), } } } -impl DbInsert for NewFunderHistory { - type MainEntity = FunderHistory; +impl DbInsert for NewInstitutionHistory { + type MainEntity = InstitutionHistory; - db_insert!(funder_history::table); + db_insert!(institution_history::table); } #[cfg(test)] @@ -137,21 +138,24 @@ mod tests { use super::*; #[test] - fn test_funder_pk() { - let funder: Funder = Default::default(); - assert_eq!(funder.pk(), funder.funder_id); + fn test_institution_pk() { + let institution: Institution = Default::default(); + assert_eq!(institution.pk(), institution.institution_id); } #[test] - fn test_new_funder_history_from_funder() { - let funder: Funder = Default::default(); + fn test_new_institution_history_from_institution() { + let institution: Institution = Default::default(); let account_id: Uuid = Default::default(); - let new_funder_history = funder.new_history_entry(&account_id); - assert_eq!(new_funder_history.funder_id, funder.funder_id); - assert_eq!(new_funder_history.account_id, account_id); + let new_institution_history = institution.new_history_entry(&account_id); assert_eq!( - new_funder_history.data, - serde_json::Value::String(serde_json::to_string(&funder).unwrap()) + new_institution_history.institution_id, + institution.institution_id + ); + assert_eq!(new_institution_history.account_id, account_id); + assert_eq!( + new_institution_history.data, + serde_json::Value::String(serde_json::to_string(&institution).unwrap()) ); } } diff --git a/thoth-api/src/model/institution/mod.rs b/thoth-api/src/model/institution/mod.rs new file mode 100644 index 00000000..975659b0 --- /dev/null +++ b/thoth-api/src/model/institution/mod.rs @@ -0,0 +1,161 @@ +use serde::Deserialize; +use serde::Serialize; +use std::fmt; +use strum::Display; +use strum::EnumString; +use uuid::Uuid; + +use crate::graphql::utils::Direction; +use crate::model::Doi; +use crate::model::Timestamp; +#[cfg(feature = "backend")] +use crate::schema::institution; +#[cfg(feature = "backend")] +use crate::schema::institution_history; + +#[cfg_attr( + feature = "backend", + derive(juniper::GraphQLEnum), + graphql(description = "Field to use when sorting institutions list") +)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, EnumString, Display)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum InstitutionField { + #[strum(serialize = "ID")] + InstitutionId, + #[strum(serialize = "Institution")] + InstitutionName, + #[strum(serialize = "DOI")] + InstitutionDoi, + CreatedAt, + UpdatedAt, +} + +#[cfg_attr(feature = "backend", derive(Queryable))] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct Institution { + pub institution_id: Uuid, + pub institution_name: String, + pub institution_doi: Option, + pub created_at: Timestamp, + pub updated_at: Timestamp, +} + +#[cfg_attr( + feature = "backend", + derive(juniper::GraphQLInputObject, Insertable), + table_name = "institution" +)] +pub struct NewInstitution { + pub institution_name: String, + pub institution_doi: Option, +} + +#[cfg_attr( + feature = "backend", + derive(juniper::GraphQLInputObject, AsChangeset), + changeset_options(treat_none_as_null = "true"), + table_name = "institution" +)] +pub struct PatchInstitution { + pub institution_id: Uuid, + pub institution_name: String, + pub institution_doi: Option, +} + +#[cfg_attr(feature = "backend", derive(Queryable))] +pub struct InstitutionHistory { + pub institution_history_id: Uuid, + pub institution_id: Uuid, + pub account_id: Uuid, + pub data: serde_json::Value, + pub timestamp: Timestamp, +} + +#[cfg_attr( + feature = "backend", + derive(Insertable), + table_name = "institution_history" +)] +pub struct NewInstitutionHistory { + pub institution_id: Uuid, + pub account_id: Uuid, + pub data: serde_json::Value, +} + +#[cfg_attr( + feature = "backend", + derive(juniper::GraphQLInputObject), + graphql(description = "Field and order to use when sorting institutions list") +)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] +pub struct InstitutionOrderBy { + pub field: InstitutionField, + pub direction: Direction, +} + +impl Default for InstitutionField { + fn default() -> Self { + InstitutionField::InstitutionName + } +} + +impl fmt::Display for Institution { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if let Some(doi) = &self.institution_doi { + write!(f, "{} - {}", &self.institution_name, doi) + } else { + write!(f, "{}", &self.institution_name) + } + } +} + +#[test] +fn test_institutionfield_default() { + let fundfield: InstitutionField = Default::default(); + assert_eq!(fundfield, InstitutionField::InstitutionName); +} + +#[test] +fn test_institutionfield_display() { + assert_eq!(format!("{}", InstitutionField::InstitutionId), "ID"); + assert_eq!( + format!("{}", InstitutionField::InstitutionName), + "Institution" + ); + assert_eq!(format!("{}", InstitutionField::InstitutionDoi), "DOI"); + assert_eq!(format!("{}", InstitutionField::CreatedAt), "CreatedAt"); + assert_eq!(format!("{}", InstitutionField::UpdatedAt), "UpdatedAt"); +} + +#[test] +fn test_institutionfield_fromstr() { + use std::str::FromStr; + assert_eq!( + InstitutionField::from_str("ID").unwrap(), + InstitutionField::InstitutionId + ); + assert_eq!( + InstitutionField::from_str("Institution").unwrap(), + InstitutionField::InstitutionName + ); + assert_eq!( + InstitutionField::from_str("DOI").unwrap(), + InstitutionField::InstitutionDoi + ); + assert_eq!( + InstitutionField::from_str("CreatedAt").unwrap(), + InstitutionField::CreatedAt + ); + assert_eq!( + InstitutionField::from_str("UpdatedAt").unwrap(), + InstitutionField::UpdatedAt + ); + assert!(InstitutionField::from_str("InstitutionID").is_err()); + assert!(InstitutionField::from_str("Website").is_err()); + assert!(InstitutionField::from_str("Fundings").is_err()); +} + +#[cfg(feature = "backend")] +pub mod crud; diff --git a/thoth-api/src/model/mod.rs b/thoth-api/src/model/mod.rs index e4a7a559..6b05e5bf 100644 --- a/thoth-api/src/model/mod.rs +++ b/thoth-api/src/model/mod.rs @@ -731,9 +731,9 @@ fn test_convert_units_from_to() { pub mod contribution; pub mod contributor; -pub mod funder; pub mod funding; pub mod imprint; +pub mod institution; pub mod issue; pub mod language; pub mod price; diff --git a/thoth-api/src/model/work/mod.rs b/thoth-api/src/model/work/mod.rs index a206d991..3e8d5748 100644 --- a/thoth-api/src/model/work/mod.rs +++ b/thoth-api/src/model/work/mod.rs @@ -6,7 +6,7 @@ use uuid::Uuid; use crate::graphql::utils::Direction; use crate::model::contribution::Contribution; -use crate::model::funding::FundingWithFunder; +use crate::model::funding::FundingWithInstitution; use crate::model::imprint::ImprintWithPublisher; use crate::model::issue::IssueWithSeries; use crate::model::language::Language; @@ -190,7 +190,7 @@ pub struct WorkWithRelations { pub contributions: Option>, pub publications: Option>, pub languages: Option>, - pub fundings: Option>, + pub fundings: Option>, pub subjects: Option>, pub issues: Option>, pub imprint: ImprintWithPublisher, diff --git a/thoth-api/src/schema.rs b/thoth-api/src/schema.rs index 59d64a3c..9d599dac 100644 --- a/thoth-api/src/schema.rs +++ b/thoth-api/src/schema.rs @@ -80,10 +80,10 @@ table! { table! { use diesel::sql_types::*; - funder (funder_id) { - funder_id -> Uuid, - funder_name -> Text, - funder_doi -> Nullable, + institution (institution_id) { + institution_id -> Uuid, + institution_name -> Text, + institution_doi -> Nullable, created_at -> Timestamptz, updated_at -> Timestamptz, } @@ -92,9 +92,9 @@ table! { table! { use diesel::sql_types::*; - funder_history (funder_history_id) { - funder_history_id -> Uuid, - funder_id -> Uuid, + institution_history (institution_history_id) { + institution_history_id -> Uuid, + institution_id -> Uuid, account_id -> Uuid, data -> Jsonb, timestamp -> Timestamptz, @@ -107,7 +107,7 @@ table! { funding (funding_id) { funding_id -> Uuid, work_id -> Uuid, - funder_id -> Uuid, + institution_id -> Uuid, program -> Nullable, project_name -> Nullable, project_shortname -> Nullable, @@ -414,9 +414,9 @@ joinable!(contribution_history -> account (account_id)); joinable!(contribution_history -> contribution (contribution_id)); joinable!(contributor_history -> account (account_id)); joinable!(contributor_history -> contributor (contributor_id)); -joinable!(funder_history -> account (account_id)); -joinable!(funder_history -> funder (funder_id)); -joinable!(funding -> funder (funder_id)); +joinable!(institution_history -> account (account_id)); +joinable!(institution_history -> institution (institution_id)); +joinable!(funding -> institution (institution_id)); joinable!(funding -> work (work_id)); joinable!(funding_history -> account (account_id)); joinable!(funding_history -> funding (funding_id)); @@ -456,8 +456,8 @@ allow_tables_to_appear_in_same_query!( contribution_history, contributor, contributor_history, - funder, - funder_history, + institution, + institution_history, funding, funding_history, imprint, diff --git a/thoth-app/src/agent/funder_activity_checker.rs b/thoth-app/src/agent/institution_activity_checker.rs similarity index 56% rename from thoth-app/src/agent/funder_activity_checker.rs rename to thoth-app/src/agent/institution_activity_checker.rs index 0e270eba..6e6c99ad 100644 --- a/thoth-app/src/agent/funder_activity_checker.rs +++ b/thoth-app/src/agent/institution_activity_checker.rs @@ -11,38 +11,38 @@ use crate::agent::notification_bus::NotificationBus; use crate::agent::notification_bus::NotificationDispatcher; use crate::agent::notification_bus::NotificationStatus; use crate::agent::notification_bus::Request as NotificationRequest; -use crate::models::funder::funder_activity_query::FetchActionFunderActivity; -use crate::models::funder::funder_activity_query::FetchFunderActivity; -use crate::models::funder::funder_activity_query::FunderActivityRequest; -use crate::models::funder::funder_activity_query::FunderActivityRequestBody; -use crate::models::funder::funder_activity_query::FunderActivityResponseData; -use crate::models::funder::funder_activity_query::Variables; +use crate::models::institution::institution_activity_query::FetchActionInstitutionActivity; +use crate::models::institution::institution_activity_query::FetchInstitutionActivity; +use crate::models::institution::institution_activity_query::InstitutionActivityRequest; +use crate::models::institution::institution_activity_query::InstitutionActivityRequestBody; +use crate::models::institution::institution_activity_query::InstitutionActivityResponseData; +use crate::models::institution::institution_activity_query::Variables; pub enum Msg { - SetFunderActivityFetchState(FetchActionFunderActivity), + SetInstitutionActivityFetchState(FetchActionInstitutionActivity), } pub enum Request { - RetrieveFunderActivity(Uuid), + RetrieveInstitutionActivity(Uuid), } -pub struct FunderActivityChecker { - agent_link: AgentLink, - fetch_funder_activity: FetchFunderActivity, +pub struct InstitutionActivityChecker { + agent_link: AgentLink, + fetch_institution_activity: FetchInstitutionActivity, subscribers: HashSet, notification_bus: NotificationDispatcher, } -impl Agent for FunderActivityChecker { +impl Agent for InstitutionActivityChecker { type Input = Request; type Message = Msg; - type Output = FunderActivityResponseData; + type Output = InstitutionActivityResponseData; type Reach = Context; fn create(link: AgentLink) -> Self { Self { agent_link: link, - fetch_funder_activity: Default::default(), + fetch_institution_activity: Default::default(), subscribers: HashSet::new(), notification_bus: NotificationBus::dispatcher(), } @@ -50,9 +50,9 @@ impl Agent for FunderActivityChecker { fn update(&mut self, msg: Self::Message) { match msg { - Msg::SetFunderActivityFetchState(fetch_state) => { - self.fetch_funder_activity.apply(fetch_state); - match self.fetch_funder_activity.as_ref().state() { + Msg::SetInstitutionActivityFetchState(fetch_state) => { + self.fetch_institution_activity.apply(fetch_state); + match self.fetch_institution_activity.as_ref().state() { FetchState::NotFetching(_) => (), FetchState::Fetching(_) => (), FetchState::Fetched(body) => { @@ -75,21 +75,21 @@ impl Agent for FunderActivityChecker { fn handle_input(&mut self, msg: Self::Input, _: HandlerId) { match msg { - Request::RetrieveFunderActivity(funder_id) => { - let body = FunderActivityRequestBody { + Request::RetrieveInstitutionActivity(institution_id) => { + let body = InstitutionActivityRequestBody { variables: Variables { - funder_id: Some(funder_id), + institution_id: Some(institution_id), }, ..Default::default() }; - let request = FunderActivityRequest { body }; - self.fetch_funder_activity = Fetch::new(request); + let request = InstitutionActivityRequest { body }; + self.fetch_institution_activity = Fetch::new(request); self.agent_link.send_future( - self.fetch_funder_activity - .fetch(Msg::SetFunderActivityFetchState), + self.fetch_institution_activity + .fetch(Msg::SetInstitutionActivityFetchState), ); self.agent_link - .send_message(Msg::SetFunderActivityFetchState(FetchAction::Fetching)); + .send_message(Msg::SetInstitutionActivityFetchState(FetchAction::Fetching)); } } } diff --git a/thoth-app/src/agent/mod.rs b/thoth-app/src/agent/mod.rs index ec3badd7..ba851ad6 100644 --- a/thoth-app/src/agent/mod.rs +++ b/thoth-app/src/agent/mod.rs @@ -63,7 +63,7 @@ macro_rules! timer_agent { } pub mod contributor_activity_checker; -pub mod funder_activity_checker; +pub mod institution_activity_checker; pub mod notification_bus; pub mod session_timer; pub mod version_timer; diff --git a/thoth-app/src/component/admin.rs b/thoth-app/src/component/admin.rs index 4db68450..fc68e54d 100644 --- a/thoth-app/src/component/admin.rs +++ b/thoth-app/src/component/admin.rs @@ -17,14 +17,14 @@ use crate::agent::notification_bus::Request; use crate::component::contributor::ContributorComponent; use crate::component::contributors::ContributorsComponent; use crate::component::dashboard::DashboardComponent; -use crate::component::funder::FunderComponent; -use crate::component::funders::FundersComponent; use crate::component::imprint::ImprintComponent; use crate::component::imprints::ImprintsComponent; +use crate::component::institution::InstitutionComponent; +use crate::component::institutions::InstitutionsComponent; use crate::component::menu::MenuComponent; use crate::component::new_contributor::NewContributorComponent; -use crate::component::new_funder::NewFunderComponent; use crate::component::new_imprint::NewImprintComponent; +use crate::component::new_institution::NewInstitutionComponent; use crate::component::new_publisher::NewPublisherComponent; use crate::component::new_series::NewSeriesComponent; use crate::component::new_work::NewWorkComponent; @@ -177,9 +177,9 @@ impl Component for AdminComponent { AdminRoute::Imprints => html!{}, AdminRoute::Imprint(id) => html!{}, AdminRoute::NewImprint => html!{}, - AdminRoute::Funders => html!{}, - AdminRoute::Funder(id) => html!{}, - AdminRoute::NewFunder => html!{}, + AdminRoute::Institutions => html!{}, + AdminRoute::Institution(id) => html!{}, + AdminRoute::NewInstitution => html!{}, AdminRoute::Publications => html!{}, AdminRoute::Publication(id) => html!{}, AdminRoute::NewPublication => { diff --git a/thoth-app/src/component/funders.rs b/thoth-app/src/component/funders.rs deleted file mode 100644 index 649546ae..00000000 --- a/thoth-app/src/component/funders.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::models::funder::funders_query::FetchActionFunders; -use crate::models::funder::funders_query::FetchFunders; -use crate::models::funder::funders_query::FundersRequest; -use crate::models::funder::funders_query::FundersRequestBody; -use crate::models::funder::funders_query::Variables; -use thoth_api::model::funder::Funder; -use thoth_api::model::funder::FunderField; -use thoth_api::model::funder::FunderOrderBy; - -pagination_component! { - FundersComponent, - Funder, - funders, - funder_count, - FundersRequest, - FetchActionFunders, - FetchFunders, - FundersRequestBody, - Variables, - SEARCH_FUNDERS, - PAGINATION_COUNT_FUNDERS, - vec![ - FunderField::FunderId.to_string(), - FunderField::FunderName.to_string(), - FunderField::FunderDoi.to_string(), - FunderField::UpdatedAt.to_string(), - ], - FunderOrderBy, - FunderField, -} diff --git a/thoth-app/src/component/fundings_form.rs b/thoth-app/src/component/fundings_form.rs index a5dea4f4..29649172 100644 --- a/thoth-app/src/component/fundings_form.rs +++ b/thoth-app/src/component/fundings_form.rs @@ -1,5 +1,5 @@ -use thoth_api::model::funder::Funder; -use thoth_api::model::funding::FundingWithFunder; +use thoth_api::model::funding::FundingWithInstitution; +use thoth_api::model::institution::Institution; use uuid::Uuid; use yew::html; use yew::prelude::*; @@ -15,11 +15,6 @@ use crate::agent::notification_bus::NotificationDispatcher; use crate::agent::notification_bus::NotificationStatus; use crate::agent::notification_bus::Request; use crate::component::utils::FormTextInput; -use crate::models::funder::funders_query::FetchActionFunders; -use crate::models::funder::funders_query::FetchFunders; -use crate::models::funder::funders_query::FundersRequest; -use crate::models::funder::funders_query::FundersRequestBody; -use crate::models::funder::funders_query::Variables; use crate::models::funding::create_funding_mutation::CreateFundingRequest; use crate::models::funding::create_funding_mutation::CreateFundingRequestBody; use crate::models::funding::create_funding_mutation::PushActionCreateFunding; @@ -30,6 +25,11 @@ use crate::models::funding::delete_funding_mutation::DeleteFundingRequestBody; use crate::models::funding::delete_funding_mutation::PushActionDeleteFunding; use crate::models::funding::delete_funding_mutation::PushDeleteFunding; use crate::models::funding::delete_funding_mutation::Variables as DeleteVariables; +use crate::models::institution::institutions_query::FetchActionInstitutions; +use crate::models::institution::institutions_query::FetchInstitutions; +use crate::models::institution::institutions_query::InstitutionsRequest; +use crate::models::institution::institutions_query::InstitutionsRequestBody; +use crate::models::institution::institutions_query::Variables; use crate::models::Dropdown; use crate::string::CANCEL_BUTTON; use crate::string::EMPTY_FUNDINGS; @@ -40,10 +40,10 @@ use super::ToOption; pub struct FundingsFormComponent { props: Props, data: FundingsFormData, - new_funding: FundingWithFunder, + new_funding: FundingWithInstitution, show_add_form: bool, show_results: bool, - fetch_funders: FetchFunders, + fetch_institutions: FetchInstitutions, push_funding: PushCreateFunding, delete_funding: PushDeleteFunding, link: ComponentLink, @@ -52,20 +52,20 @@ pub struct FundingsFormComponent { #[derive(Default)] struct FundingsFormData { - funders: Vec, + institutions: Vec, } pub enum Msg { ToggleAddFormDisplay(bool), - SetFundersFetchState(FetchActionFunders), - GetFunders, + SetInstitutionsFetchState(FetchActionInstitutions), + GetInstitutions, ToggleSearchResultDisplay(bool), - SearchFunder(String), + SearchInstitution(String), SetFundingPushState(PushActionCreateFunding), CreateFunding, SetFundingDeleteState(PushActionDeleteFunding), DeleteFunding(Uuid), - AddFunding(Funder), + AddFunding(Institution), ChangeProgram(String), ChangeProjectName(String), ChangeProjectShortname(String), @@ -75,9 +75,9 @@ pub enum Msg { #[derive(Clone, Properties, PartialEq)] pub struct Props { - pub fundings: Option>, + pub fundings: Option>, pub work_id: Uuid, - pub update_fundings: Callback>>, + pub update_fundings: Callback>>, } impl Component for FundingsFormComponent { @@ -86,15 +86,15 @@ impl Component for FundingsFormComponent { fn create(props: Self::Properties, link: ComponentLink) -> Self { let data: FundingsFormData = Default::default(); - let new_funding: FundingWithFunder = Default::default(); + let new_funding: FundingWithInstitution = Default::default(); let show_add_form = false; let show_results = false; - let fetch_funders = Default::default(); + let fetch_institutions = Default::default(); let push_funding = Default::default(); let delete_funding = Default::default(); let notification_bus = NotificationBus::dispatcher(); - link.send_message(Msg::GetFunders); + link.send_message(Msg::GetInstitutions); FundingsFormComponent { props, @@ -102,7 +102,7 @@ impl Component for FundingsFormComponent { new_funding, show_add_form, show_results, - fetch_funders, + fetch_institutions, push_funding, delete_funding, link, @@ -116,21 +116,23 @@ impl Component for FundingsFormComponent { self.show_add_form = value; true } - Msg::SetFundersFetchState(fetch_state) => { - self.fetch_funders.apply(fetch_state); - self.data.funders = match self.fetch_funders.clone().state() { + Msg::SetInstitutionsFetchState(fetch_state) => { + self.fetch_institutions.apply(fetch_state); + self.data.institutions = match self.fetch_institutions.clone().state() { FetchState::NotFetching(_) => vec![], FetchState::Fetching(_) => vec![], - FetchState::Fetched(body) => body.data.funders, + FetchState::Fetched(body) => body.data.institutions, FetchState::Failed(_, _err) => vec![], }; true } - Msg::GetFunders => { + Msg::GetInstitutions => { + self.link.send_future( + self.fetch_institutions + .fetch(Msg::SetInstitutionsFetchState), + ); self.link - .send_future(self.fetch_funders.fetch(Msg::SetFundersFetchState)); - self.link - .send_message(Msg::SetFundersFetchState(FetchAction::Fetching)); + .send_message(Msg::SetInstitutionsFetchState(FetchAction::Fetching)); false } Msg::SetFundingPushState(fetch_state) => { @@ -141,7 +143,7 @@ impl Component for FundingsFormComponent { FetchState::Fetched(body) => match &body.data.create_funding { Some(i) => { let funding = i.clone(); - let mut fundings: Vec = + let mut fundings: Vec = self.props.fundings.clone().unwrap_or_default(); fundings.push(funding); self.props.update_fundings.emit(Some(fundings)); @@ -171,7 +173,7 @@ impl Component for FundingsFormComponent { let body = CreateFundingRequestBody { variables: CreateVariables { work_id: self.props.work_id, - funder_id: self.new_funding.funder_id, + institution_id: self.new_funding.institution_id, program: self.new_funding.program.clone(), project_name: self.new_funding.project_name.clone(), project_shortname: self.new_funding.project_shortname.clone(), @@ -195,7 +197,7 @@ impl Component for FundingsFormComponent { FetchState::Fetching(_) => false, FetchState::Fetched(body) => match &body.data.delete_funding { Some(funding) => { - let to_keep: Vec = self + let to_keep: Vec = self .props .fundings .clone() @@ -236,9 +238,9 @@ impl Component for FundingsFormComponent { .send_message(Msg::SetFundingDeleteState(FetchAction::Fetching)); false } - Msg::AddFunding(funder) => { - self.new_funding.funder_id = funder.funder_id; - self.new_funding.funder = funder; + Msg::AddFunding(institution) => { + self.new_funding.institution_id = institution.institution_id; + self.new_funding.institution = institution; self.link.send_message(Msg::ToggleAddFormDisplay(true)); true } @@ -246,8 +248,8 @@ impl Component for FundingsFormComponent { self.show_results = value; true } - Msg::SearchFunder(value) => { - let body = FundersRequestBody { + Msg::SearchInstitution(value) => { + let body = InstitutionsRequestBody { variables: Variables { filter: Some(value), limit: Some(9999), @@ -255,9 +257,9 @@ impl Component for FundingsFormComponent { }, ..Default::default() }; - let request = FundersRequest { body }; - self.fetch_funders = Fetch::new(request); - self.link.send_message(Msg::GetFunders); + let request = InstitutionsRequest { body }; + self.fetch_institutions = Fetch::new(request); + self.link.send_message(Msg::GetInstitutions); false } Msg::ChangeProgram(val) => self.new_funding.program.neq_assign(val.to_opt_string()), @@ -303,10 +305,10 @@ impl Component for FundingsFormComponent { @@ -316,14 +318,14 @@ impl Component for FundingsFormComponent {

-