Skip to content

Commit

Permalink
Merge pull request #523 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
fix: Extending drafts to include shared project drafts
  • Loading branch information
NishaSharma14 authored Oct 20, 2022
2 parents cf84c7c + cade25c commit 4d00f79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/DraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function all(Request $request)
->where('owner_id', $user_id)
->first();

$sharedDrafts = $user->sharedDrafts();

if (! $defaultDraft) {
$id = Str::uuid();
$environment = env('APP_ENV', 'local');
Expand All @@ -71,6 +73,7 @@ public function all(Request $request)

return response()->json([
'drafts' => $drafts,
'sharedDrafts' => $sharedDrafts,
'default' => $defaultDraft,
]);
}
Expand Down
11 changes: 11 additions & 0 deletions app/Models/HasProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public function sharedProjects()
return $this->projects()->wherePivot('role', '!=', 'creator');
}

/**
* User model and Drafts relationship - many to many
*
* @var array
*/
public function sharedDrafts()
{
$sharedProjects = $this->projects()->wherePivot('role', '!=', 'creator');
return Draft::whereIn('id', $sharedProjects->pluck('draft_id'))->get();
}

/**
* User model and Projects relationship - many to many
*
Expand Down
6 changes: 6 additions & 0 deletions resources/js/Shared/Submission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1633,10 +1633,16 @@ export default {
const initialise = (data) => {
this.fetchDrafts().then((response) => {
this.drafts = response.data.drafts;
this.sharedDrafts = response.data.sharedDrafts;
if (data.draft_id) {
let selectedDraft = this.drafts.find(
(d) => d.id == data.draft_id
);
if(!selectedDraft){
selectedDraft = this.sharedDrafts.find(
(d) => d.id == data.draft_id
);
}
this.selectDraft(selectedDraft);
this.loading = false;
this.toggleOpenCreateDatasetDialog();
Expand Down

0 comments on commit 4d00f79

Please sign in to comment.