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

Enabled structure deletion in the studies - Fixes #246 #376

Merged
merged 2 commits into from
Aug 23, 2022
Merged
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
10 changes: 10 additions & 0 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public function moleculeStore(Request $request, Study $study)
return $sample->molecules;
}

public function moleculeDetach(Request $request, Study $study, Molecule $molecule)
{
if ($molecule) {
$sample = $study->sample;
$sample->molecules()->detach([$molecule->id]);
$sample = $sample->fresh();
return $sample->molecules;
}
}

public function files(Request $request, Study $study)
{
if (! Gate::forUser($request->user())->check('viewStudy', $study)) {
Expand Down
77 changes: 57 additions & 20 deletions resources/js/Pages/Study/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<h3
class="text-lg leading-6 font-medium text-gray-900"
>
Structures
Sample chemical composition
</h3>
</div>
</div>
Expand Down Expand Up @@ -318,22 +318,15 @@
"
class="relative"
>
<img
class="h-10 w-10 rounded-full bg-gray-400 flex items-center justify-center ring-8 ring-white"
:src="
'https://ui-avatars.com/api/?name=' +
(
'0' +
molecule
.pivot
.percentage_composition
).slice(
-2
) +
'%2BUser&color=7F9CF5&background=EBF4FF'
"
alt=""
/>
<div
class="rounded-full border p-2 z-10 bg-gray-100 text-sm"
>
{{
molecule
.pivot
.percentage_composition
}}%
</div>
</div>
<div
class="min-w-0 flex-1"
Expand Down Expand Up @@ -365,11 +358,30 @@
></span>
</div>
</div>
<button
class="inline-flex items-center px-2.5 py-1.5 border border-gray-300 shadow-sm text-xs font-medium rounded text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
@click="
deleteMolecule(
molecule
)
"
>
<TrashIcon
class="w-4 h-4 inline mr-1"
></TrashIcon
>Delete
</button>
</div>
</div>
</div>
</li>
</ul>
<div
class="rounded-full border p-2 z-10 bg-gray-100 text-sm mt-14 text-center"
>
Sample chemical
composition
</div>
</div>
<div v-else>
<div
Expand Down Expand Up @@ -412,6 +424,16 @@
class="shadow-sm focus:ring-teal-500 focus:border-teal-500 block w-full sm:text-sm border-gray-300 rounded-md"
@blur="loadSmiles"
/>
<button
v-if="
smiles &&
smiles != ''
"
class="inline-flex items-center px-2.5 py-1.5 border border-gray-300 shadow-sm text-xs font-medium rounded text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 mt-2"
@click="loadSmiles"
>
Load Structure
</button>
</div>
</div>
<div class="relative">
Expand Down Expand Up @@ -460,7 +482,7 @@
class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-teal-600 hover:bg-teal-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="saveMolecule"
>
SAVE
ADD
</button>
</div>
</div>
Expand Down Expand Up @@ -521,7 +543,7 @@
</template>

<script>
import { PlusSmIcon } from "@heroicons/vue/solid";
import { PlusSmIcon, TrashIcon } from "@heroicons/vue/solid";
import StudyContent from "@/Pages/Study/Content.vue";
import slider from "vue3-slider";
import OCL from "openchemlib/full";
Expand All @@ -532,6 +554,7 @@ export default {
ToolTip,
PlusSmIcon,
slider,
TrashIcon,
},
props: [
"study",
Expand All @@ -558,7 +581,6 @@ export default {
this.study.sample.molecules.forEach((mol) => {
totalCount += parseInt(mol.pivot.percentage_composition);
});
console.log(totalCount);
return 100 - totalCount;
} else {
return 100;
Expand Down Expand Up @@ -597,6 +619,21 @@ export default {
console.log(molecule);
}
},
deleteMolecule(mol) {
axios
.delete(
"/dashboard/studies/" +
this.study.id +
"/molecule/" +
mol.id
)
.then((res) => {
this.study.sample.molecules = res.data;
this.smiles = "";
this.percentage = 0;
this.editor.setSmiles("");
});
},
saveMolecule() {
let mol = this.editor.getMolFile();
axios
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/Study/MolecularIdentifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
Molecular Identifications
</h2>
<!-- <p class="mt-1 text-sm text-gray-500">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod.
</p> -->
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod.
</p> -->
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@

Route::post('studies/{study}/molecule', [StudyController::class, 'moleculeStore'])
->name('study-molecule.store');
Route::delete('studies/{study}/molecule/{molecule}', [StudyController::class, 'moleculeDetach'])
->name('study-molecule.delete');

Route::get('/study-invitations/{invitation}', [StudyInvitationController::class, 'acceptInvitation'])
->middleware(['signed'])
Expand Down