Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new samples to public projects #1181

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function validation(Request $request, Project $project)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand Down Expand Up @@ -302,7 +302,7 @@ public function validationReport(Request $request, Project $project)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand All @@ -327,7 +327,13 @@ public function publish(Request $request, Project $project, PublishProject $publ
if ($project) {
$input = $request->all();
$release_date = $input['release_date'];
$enableProjectMode = $request->get('enableProjectMode');
$selected_project_id = $input['selected_project_id'];
$selected_project_license_id = $input['license_id'];
if ($selected_project_id) {
$enableProjectMode = false;
} else {
$enableProjectMode = $request->get('enableProjectMode');
}
if ($enableProjectMode) {
$validation = $project->validation;
$validation->process();
Expand Down Expand Up @@ -363,10 +369,15 @@ public function publish(Request $request, Project $project, PublishProject $publ
$validation = $validation->fresh();

foreach ($project->studies as $study) {
$study->license_id = $project->license_id;
if ($selected_project_id) {
$study->location = $selected_project_id;
$study->license_id = $selected_project_license_id;
} else {
$study->license_id = $project->license_id;
}
$study->save();
foreach ($study->datasets as $dataset) {
$dataset->license_id = $project->license_id;
$dataset->license_id = $study->license_id;
$dataset->save();
}
}
Expand All @@ -380,6 +391,7 @@ public function publish(Request $request, Project $project, PublishProject $publ
}
// add license check
if ($status) {

ProcessSubmission::dispatch($project);

return response()->json([
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use App\Models\Project;
use App\Models\User;

class UserController extends Controller
{
/**
* Retrieve the names of public projects owned by the user
*/
public function retrieveProjects(User $user)
{
return Project::where('owner_id', $user->id)
->where('is_public', true)
->get(['id', 'name', 'description', 'license_id'])
->map(function ($project) {
return [
'id' => $project->id,
'name' => $project->name,
'description' => $project->description,
'license_id' => $project->license_id,
];
})
->toArray();
}
}
32 changes: 27 additions & 5 deletions app/Jobs/ProcessSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProcessSubmission implements ShouldBeUnique, ShouldQueue
public function __construct(Project $project)
{
$this->project = $project;

}

/**
Expand All @@ -45,7 +46,6 @@ public function __construct(Project $project)
public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishProject $projectPublisher, PublishStudy $studyPublisher)
{
$project = $this->project;

$project->status = 'processing';
$project->save();

Expand Down Expand Up @@ -117,16 +117,19 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr
$logs = 'Moving files in progress';

if ($project) {

$_studies = $project->studies;
if ($draft) {
$environment = env('APP_ENV', 'local');

foreach ($_studies as $study) {
// $study->users()->sync($project->user()->getDictionary());

$studyPath = preg_replace(
'~//+~',
'/',
$environment.'/samples/'.$study->uuid

);

$studyFSObjects = FileSystemObject::with('children')
Expand Down Expand Up @@ -154,11 +157,15 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr
}
$study->process_logs = $process_logs;
$study->draft_id = null;
$study->project_id = null;
if ($study->location) {
$study->project_id = $study->location;
} else {
$study->project_id = null;
}

foreach ($study->datasets as $dataset) {
$dataset->draft_id = null;
$dataset->project_id = null;
$dataset->project_id = $study->project_id;
$dataset->save();
}

Expand All @@ -167,16 +174,31 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr
}
}
$assigner->assign($_studies);

$release_date = Carbon::parse($project->release_date);
foreach ($_studies as $study) {
if ($study->location) {
$release_date = Carbon::now();
$study->release_date = $release_date;
}
}

if ($release_date->isPast()) {
foreach ($_studies as $study) {
$studyPublisher->publish($study);
}
}
$updater->update($_studies);
//Notification::send($this->prepareSendList($project), new StudyPublishNotification($_studies));
event(new StudyPublish($_studies, $this->prepareSendList($project)));

if ($study->location) {
$selected_project = Project::where([['id', $study->location]])->firstOrFail();
$updater->update($selected_project);
event(new StudyPublish($_studies, $this->prepareSendList($selected_project)));
$study->location = null;
} else {
event(new StudyPublish($_studies, $this->prepareSendList($project)));
$updater->update($_studies);
}

$project->delete();
$draft->delete();
Expand Down
30 changes: 30 additions & 0 deletions resources/js/Pages/Publish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
@blur="updateDraft"
/>
</div>
<jet-button
v-if="publishForm.enableProjectMode"
class="bg-gray-500 -mt-10 hover:bg-gray-700 float-right"
@click="toggleManageProject"
>
{{ "+ Add to existing project" }}
</jet-button>

<div v-if="publishForm.enableProjectMode">
<div class="p-4 bg-gray-100 rounded-md">
<div id="project-name" class="mb-3">
Expand Down Expand Up @@ -677,6 +685,11 @@
ref="manageCitationElement"
:project="project"
/>
<manage-project
ref="manageProjectElement"
:project="project"
@selected_project="handleProjectSelected"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -790,6 +803,7 @@ import Validation from "@/Shared/Validation.vue";
import Datepicker from "@vuepic/vue-datepicker";
import "@vuepic/vue-datepicker/dist/main.css";
import ManageAuthor from "@/Shared/ManageAuthor.vue";
import ManageProject from "@/Shared/ManageProject.vue";
import ToolTip from "@/Shared/ToolTip.vue";
import ManageCitation from "@/Shared/ManageCitation.vue";
import Citation from "@/Shared/Citation.vue";
Expand Down Expand Up @@ -856,15 +870,19 @@ export default {
CitationCard,
JetConfirmationModal,
JetSuccessButton,
ManageProject,
},
props: ["user", "team", "project", "teamRole", "draft"],

setup() {
const manageAuthorElement = ref(null);
const manageCitationElement = ref(null);
const manageProjectElement = ref(null);

return {
manageAuthorElement,
manageCitationElement,
manageProjectElement,
};
},

Expand All @@ -886,6 +904,7 @@ export default {
terms: false,
enableProjectMode: false,
release_date: this.setReleaseDate(),
selected_project_id: null,
}),
licenses: null,
license: null,
Expand Down Expand Up @@ -1121,6 +1140,9 @@ export default {
toggleManageCitation() {
this.manageCitationElement.toggleDialog();
},
toggleManageProject() {
this.manageProjectElement.toggleDialog();
},
publish() {
this.showPublishConfirmationModal = false;
if (this.publishForm.conditions && this.publishForm.terms) {
Expand Down Expand Up @@ -1149,6 +1171,14 @@ export default {
return true;
}
},

handleProjectSelected(selected_project) {
this.publishForm.selected_project_id = selected_project.id;
this.publishForm.license_id = selected_project.license_id;
this.publishForm.conditions = true;
this.publishForm.terms = true;
this.publish();
},
// trackProject() {
// axios
// .get("/projects/status/" + this.project.id + "/queue")
Expand Down
Loading