Skip to content

Commit

Permalink
refactor: remove ember-data:deprecate-promise-many-array-behaviors de…
Browse files Browse the repository at this point in the history
…precation
  • Loading branch information
jaredgalanis committed May 28, 2024
1 parent d948853 commit 1f0da8c
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 88 deletions.
10 changes: 5 additions & 5 deletions app/components/submissions-repoid-cell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export default class SubmissionsRepoidCell extends Component {
jscholarshipCheckString = '/handle/';

@action
setUpRepoidCell() {
const publicationId = get(this, 'args.record.publication.id');
if (!publicationId) {
async setUpRepoidCell() {
const publication = await this.args.record.publication;
if (!publication?.id) {
if (!(get(this, 'isDestroyed') || get(this, 'isDestroying'))) {
set(this, 'repoCopies', []);
this.repoCopies = [];
return;
}
}

const query = {
filter: {
repositoryCopy: `publication.id==${publicationId}`,
repositoryCopy: `publication.id==${publication.id}`,
},
};

Expand Down
9 changes: 5 additions & 4 deletions app/components/workflow-grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default class WorkflowGrants extends Component {
setup = function* () {
this.contactUrl = this.appStaticConfig?.config?.branding?.pages?.contactUrl;

if (get(this, 'args.submission.submitter.id')) {
const submitter = yield this.args.submission.submitter;
if (submitter?.id) {
yield this.updateGrants.perform();
}

Expand All @@ -109,7 +110,7 @@ export default class WorkflowGrants extends Component {
updateGrants = task(async () => {
let info = {};

const userId = get(this, 'args.submission.submitter.id');
const userId = await this.args.submission.submitter.id;
// TODO: Ignore date filter for now ( >= 2011-01-01 )
const grantQuery = {
filter: {
Expand All @@ -125,8 +126,8 @@ export default class WorkflowGrants extends Component {

this.submitterGrants = results;
// TODO: How do we get pagination to work with store.query like this?
set(this, 'totalGrants', info.total);
set(this, 'pageCount', Math.ceil(info.total / this.pageSize));
this.totalGrants = info.total;
this.pageCount = Math.ceil(info.total / this.pageSize);
});

/**
Expand Down
5 changes: 3 additions & 2 deletions app/components/workflow-metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ export default class WorkflowMetadata extends Component {
// 10.4137/CMC.S38446
// 10.1039/c7an01256j
if (!this.schemas) {
const repos = this.args.submission.repositories.map((repo) => repo.id);
const repositories = yield this.args.submission.repositories;
const repoIds = repositories.map((repo) => repo.id);

// Load schemas by calling the Schema service
try {
const schemas = yield this.metadataSchema.getMetadataSchemas(repos);
const schemas = yield this.metadataSchema.getMetadataSchemas(repoIds);

const requiresJournal =
schemas.findIndex((schema) => 'required' in schema && schema.required.includes('journal-title')) != -1;
Expand Down
12 changes: 6 additions & 6 deletions app/components/workflow-repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export default class WorkflowRepositories extends Component {
* are valid
*/
@action
setupRepos() {
async setupRepos() {
this.addedRepos = this.getAddedRepositories();
const currentRepos = this.args.submission.repositories.slice();
const currentRepos = await this.args.submission.repositories;

const opt = this.args.optionalRepositories;
const req = this.args.requiredRepositories;
Expand Down Expand Up @@ -206,8 +206,8 @@ export default class WorkflowRepositories extends Component {
* @param {Repository} repository
* @param {boolean} setMaxStep should we modify 'maxStep' in the workflow?
*/
addRepository(repository, setMaxStep) {
const repos = this.args.submission.repositories.slice();
async addRepository(repository, setMaxStep) {
const repos = await this.args.submission.repositories;

if (!repos.includes(repository)) {
this.args.submission.repositories = [repository, ...repos];
Expand All @@ -223,8 +223,8 @@ export default class WorkflowRepositories extends Component {
* @param {Repository} repository
* @param {boolean} setMaxStep should we modify 'maxStep' in the workflow?
*/
removeRepository(repository, setMaxStep) {
const repositories = this.args.submission.repositories.slice();
async removeRepository(repository, setMaxStep) {
const repositories = await this.args.submission.repositories;
this.args.submission.repositories = repositories.filter((r) => r.name !== repository.name);
if (setMaxStep) {
this.workflow.setMaxStep(4);
Expand Down
69 changes: 37 additions & 32 deletions app/components/workflow-review/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class WorkflowReview extends Component {
@tracked isValidated = [];
@tracked filesTemp = this.workflow.filesTemp;
@tracked hasVisitedWeblink = false;
@tracked repositories = this.args.submission.repositories;

get parsedFiles() {
let newArr = [];
Expand All @@ -38,12 +39,14 @@ export default class WorkflowReview extends Component {
}

get weblinkRepos() {
const repos = get(this, 'args.submission.repositories').filter((repo) => repo.get('_isWebLink'));
return repos;
const webLinkRepos = this.repositories.filter((repo) => repo._isWebLink);

return webLinkRepos;
}

get mustVisitWeblink() {
const weblinkExists = get(this, 'weblinkRepos.length') > 0;
const weblinkExists = this.weblinkRepos.length > 0;

const isSubmitter = get(this, 'currentUser.user.id') === get(this, 'args.submission.submitter.id');
return weblinkExists && isSubmitter;
}
Expand Down Expand Up @@ -101,24 +104,25 @@ export default class WorkflowReview extends Component {
}

// User is submitting on own behalf. Must get repository agreements.
let reposWithAgreementText = get(this, 'args.submission.repositories')
.filter((repo) => !repo.get('_isWebLink') && repo.get('agreementText'))
const repos = yield this.args.submission.repositories;
let reposWithAgreementText = repos
.filter((repo) => !repo._isWebLink && repo.agreementText)
.map((repo) => ({
id: repo.get('name'),
title: `Deposit requirements for ${repo.get('name')}`,
html: `<div class="form-control deposit-agreement-content py-4 mt-4">${repo.get('agreementText')}</div>`,
id: repo.name,
title: `Deposit requirements for ${repo.name}`,
html: `<div class="form-control deposit-agreement-content py-4 mt-4">${repo.agreementText}</div>`,
}));

let reposWithoutAgreementText = get(this, 'args.submission.repositories')
.filter((repo) => !repo.get('_isWebLink') && !repo.get('agreementText'))
let reposWithoutAgreementText = repos
.filter((repo) => !repo._isWebLink && !repo.agreementText)
.map((repo) => ({
id: repo.get('name'),
id: repo.name,
}));

let reposWithWebLink = get(this, 'args.submission.repositories')
.filter((repo) => repo.get('_isWebLink'))
let reposWithWebLink = repos
.filter((repo) => repo._isWebLink)
.map((repo) => ({
id: repo.get('name'),
id: repo.name,
}));

const result = yield swal
Expand Down Expand Up @@ -181,22 +185,23 @@ export default class WorkflowReview extends Component {
* It is assumed that the user has done the necessary steps for each web-link repository,
* so those are also kept in the list
*/
set(
this,
'args.submission.repositories',
get(this, 'args.submission.repositories').filter((repo) => {
if (repo.get('_isWebLink')) {
return true;
}
let temp = reposWithAgreementText.map((x) => x.id).includes(repo.get('name'));
if (!temp) {
return true;
} else if (reposThatUserAgreedToDeposit.map((r) => r.id).includes(repo.get('name'))) {
return true;
}
return false;
})
);

const repos = yield this.args.submission.repositories;

const filteredRepos = repos.filter((repo) => {
if (repo._isWebLink) {
return true;
}
let temp = reposWithAgreementText.map((x) => x.id).includes(repo.name);
if (!temp) {
return true;
} else if (reposThatUserAgreedToDeposit.map((r) => r.id).includes(repo.name)) {
return true;
}
return false;
});

this.args.submission.repositories = filteredRepos;

this.args.submit();
} else {
Expand Down Expand Up @@ -271,14 +276,14 @@ export default class WorkflowReview extends Component {
return;
}
// Go to the weblink repo
this.externalRepoMap[repo.get('id')] = true;
this.externalRepoMap[repo.id] = true;
const allLinksVisited = Object.values(this.externalRepoMap).every((val) => val === true);
if (allLinksVisited) {
this.hasVisitedWeblink = true;
}
$('#externalSubmission').modal('hide');

var win = window.open(repo.get('url'), '_blank');
var win = window.open(repo.url, '_blank');

if (win) {
win.focus();
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ export default class SubmissionsDetail extends Controller {
/**
* Get enough information about 'web-link' repositories to display to a user.
*/
get externalSubmissionsMetadata() {
async externalSubmissionsMetadata() {
let result = [];

this.repositories
const repos = await this.model.sub.repositories;
repos
.filter((repo) => repo._isWebLink)
.forEach((repo) => {
result.push({
Expand Down
20 changes: 11 additions & 9 deletions app/controllers/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export default class SubmissionsNew extends Controller {
@tracked user = this.currentUser.user;
@tracked submitter = this.model.newSubmission.submitter;
@tracked covid = null;
@tracked filesTemp = get(this, 'workflow.filesTemp');
@tracked filesTemp = this.workflow.filesTemp;

get userIsSubmitter() {
return get(this, 'model.newSubmission.submitter.id') === this.user.id;
async userIsSubmitter() {
const submitter = await this.model.newSubmission.submitter;
return submitter?.id === this.user.id;
}

/**
Expand Down Expand Up @@ -94,25 +95,26 @@ export default class SubmissionsNew extends Controller {
'warning'
);
} else {
let sub = get(this, 'model.newSubmission');
let pub = get(this, 'model.publication');
let sub = this.model.newSubmission;
let pub = this.model.publication;
let files = this.filesTemp;
let comment = this.comment;

this.set('uploading', true);
this.set('waitingMessage', 'Saving your submission');

await get(this, 'submissionHandler.submit')
await this.submissionHandler.submit
.perform(sub, pub, files, comment)
.then(() => {
set(this, 'uploading', false);
set(this, 'comment', '');
set(this, 'workflow.filesTemp', []);
this.router.transitionTo('thanks', { queryParams: { submission: get(sub, 'id') } });
this.router.transitionTo('thanks', { queryParams: { submission: sub.id } });
})
.catch((error) => {
this.set('uploading', false);

console.error(error.stack);
this.flashMessages.danger(`Submission failed: ${error.message}`);

const elements = document.querySelectorAll('.block-user-input');
Expand All @@ -125,7 +127,7 @@ export default class SubmissionsNew extends Controller {

@action
async abort() {
const submission = get(this, 'model.newSubmission');
const submission = this.model.newSubmission;
const ignoreList = this.searchHelper;

let result = await swal({
Expand All @@ -140,7 +142,7 @@ export default class SubmissionsNew extends Controller {
ignoreList.clearIgnore();
if (submission.id) {
await this.submissionHandler.deleteSubmission(submission);
ignoreList.ignore(get(submission, 'id'));
ignoreList.ignore(submission.id);
}
this.router.transitionTo('submissions');
}
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/submissions/new/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ export default class SubmissionsNewFiles extends Controller {
async validateAndLoadTab(gotoTab) {
let needValidation = this.needValidation;
if (needValidation) {
let files = this.files;
let manuscriptFiles = [...this.newFiles, ...this.model.files.slice()].filter(
(file) => file && get(file, 'fileRole') === 'manuscript'
);

if (manuscriptFiles.length == 0 && !this.parent.userIsSubmitter) {
const submitter = await this.parent.userIsSubmitter();

if (manuscriptFiles.length == 0 && !submitter) {
let result = await swal({
title: 'No manuscript present',
text: 'If no manuscript is attached, the designated submitter will need to add one before final submission',
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/submissions/new/repositories.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export default class SubmissionsNewRepositories extends Controller {
* Do some light processing on the repository containers, such as adding the names of funders
* that both are associated with the submission AND associated with each repository.
*/
@computed('model.requiredRepositories')
get requiredRepositories() {
let req = get(this, 'model.requiredRepositories');
let req = this.model.requiredRepositories;
const submission = this.submission;

return req.map((repo) => ({
Expand Down Expand Up @@ -121,8 +120,10 @@ export default class SubmissionsNewRepositories extends Controller {
this.parent.updateCovidSubmission();
}

_getFunderNamesForRepo(repo, submission) {
const funders = get(submission, 'grants').map((grant) => get(grant, 'primaryFunder'));
async _getFunderNamesForRepo(repo, submission) {
const grants = await submission.grants;

const funders = grants.map((grant) => get(grant, 'primaryFunder'));
const fundersWithRepos = funders.filter((funder) => get(funder, 'policy.repositories'));
// List of funders that include this repository
const fundersWithOurRepo = fundersWithRepos.filter(
Expand Down
2 changes: 1 addition & 1 deletion app/deprecation-workflow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow';

setupDeprecationWorkflow({
workflow: [{ handler: 'silence', matchId: 'ember-data:deprecate-promise-many-array-behaviors' }],
workflow: [{ handler: 'throw', matchId: 'ember-data:deprecate-promise-many-array-behaviors' }],
});
2 changes: 1 addition & 1 deletion app/models/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class SubmissionModel extends Model {
@belongsTo('publication', { async: false, inverse: null }) publication;

@hasMany('user', { async: false, inverse: null }) preparers;
@hasMany('repository', { async: true, inverse: null }) repositories;
@hasMany('repository', { async: false, inverse: null }) repositories;
@hasMany('policy', { async: false, inverse: null }) effectivePolicies;
// not on this model on API
@hasMany('submissionEvent', {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/submissions/new/repositories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class RepositoriesRoute extends CheckSessionRoute {
const parentModel = this.modelFor('submissions.new');
const submission = parentModel.newSubmission;

const repoPromise = await get(this, 'policyService.getRepositories').perform(submission);
const repoPromise = await this.policyService.getRepositories.perform(submission);

return hash({
newSubmission: submission,
Expand Down
2 changes: 1 addition & 1 deletion app/services/metadata-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default class MetadataSchemaService extends Service {
'volume',
];

const repos = await submission.repositories.slice();
const repos = await submission.repositories;
const schemas = await this.getMetadataSchemas(repos);
const titleMap = this.getFieldTitleMap(schemas);
const metadata = JSON.parse(submission.metadata);
Expand Down
Loading

0 comments on commit 1f0da8c

Please sign in to comment.