Commit c3a8c44b authored by ZeMKI's avatar ZeMKI
Browse files

Leave study

* now invited users can leave studies.
parent 781f358e
......@@ -46,6 +46,7 @@ class StudyController extends Controller
art_urls.url as url,
first_opened_at,
submitted_at,
art_urls.created_at,
code
from art_urls
inner join study_interview_public_url
......@@ -176,6 +177,12 @@ class StudyController extends Controller
$postSortQuestions[0]['type'] = 'postsort';
$this->saveQuestionsAnswers($presortQuestions, $newStudy);
$this->saveQuestionsAnswers($postSortQuestions, $newStudy);
if ($request->input('sorting.qsortaskextremes'))
{
// create question extreme and 1 answer associated.
Question::storeExtremeQuestion($request->input('sorting.qsortextremequestion'),$newStudy);
}
return response()->json(['message' => 'Study Saved!', 'studyid' => $newStudy->id], 200);
}
......@@ -226,6 +233,7 @@ class StudyController extends Controller
$question->save();
$this->saveAnswers($questionToSave, $question);
}
}
}
......@@ -291,7 +299,6 @@ class StudyController extends Controller
$data['study']['sorting'] = $study->sortings;
$data['study']['tokens'] = Token::formatForEdit($data['study']['tokens']);
$data['study']['q'] = Question::formatForEdit($study);
ray($data['study']['q']);
$data['isedit'] = 'true';
$data['presetimages'] = Helper::getPresetImages();
$data['classifiers'] = Helper::getClassifiers();
......@@ -333,6 +340,11 @@ class StudyController extends Controller
$postsortQuestions[0]['type'] = 'postsort';
$this->saveQuestionsAnswers($presortQuestions, $study, true);
$this->saveQuestionsAnswers($postsortQuestions, $study, true);
if ($request->input('sorting.qsortaskextremes'))
{
// create question extreme and 1 answer associated.
Question::storeExtremeQuestion($request->input('sorting.qsortextremequestion'),$study);
}
return response()->json(['message' => 'Study Updated!', 'studyid' => $study->id], 200);
}
......@@ -444,7 +456,10 @@ class StudyController extends Controller
public function removeFromStudy(Request $request)
{
if(!auth()->user()->is(Study::find($request->input('study'))->creator())) return response()->json(['message' => __('Not authorized!')], 403);
$user_is_not_invited = !in_array(Study::find($request->input('study'))->id, auth()->user()->invites()->pluck('study_id')->toArray());
if($user_is_not_invited && !auth()->user()->is(Study::find($request->input('study'))->creator()) ) return response()->json(['message' => __('Not authorized!')], 403);
$user = User::where('email', '=', $request->email)->first();
if ($user)
......
......@@ -187,6 +187,43 @@ window.app = new Vue({
console.log('show modal parent');
},
}, methods: {
confirmLeaveProject: function (userToDetach, study) {
let confirmDelete = this.$buefy.dialog.confirm({
title: this.trans("Confirm Leave"),
message: this.trans("Are you sure you want to leave this study?"),
cancelText: this.trans("No"),
confirmText: this.trans("YES remove me"),
hasIcon: true,
type: "is-danger",
onConfirm: () => this.detachUser(userToDetach, study),
});
},
detachUser: function (userToDetach, study) {
let self = this;
window.axios
.post(
window.location.origin +
self.productionUrl +
"/studies/invite/" +
userToDetach.id,
{
email: userToDetach.email,
study: study,
}
)
.then((response) => {
self.$buefy.snackbar.open(response.data.message);
setTimeout(function () {
window.location.reload();
}, 1000);
})
.catch(function (error) {
self.$buefy.snackbar.open(
"There it was an error during the request - refresh page and try again"
);
});
},
iWantNewsletter(will) {
let subscribed = will === 'true';
......
......@@ -47,7 +47,7 @@
@click.prevent="setinterviewdname({{$study->id}})">
<div
class="min-w-full text-center bg-green-600 hover:text-gray-300 hover:bg-green-900 text-2xl font-extrabold">
{{ __('New Interview') }}
{{ __('new interview') }}
</div>
</a>
......@@ -56,11 +56,20 @@
@click="toggleModal({{$study->id}})">
<div
class="min-w-full text-center bg-green-500 hover:text-gray-300 hover:bg-green-800 modal-open text-2xl font-extrabold">
{{ __('New Public Url') }}
{{ __('new public url') }}
</div>
</a>
<a class="select-none text-white mt-2 inline min-w-full hover:no-underline uppercase md:lowercase sm:lowercase sm:text-base md:text-xl lg:text-2xl font-extrabold"
href="#"
@click="confirmLeaveProject({{auth()->user()}},{{$study->id}})">
<div
class="min-w-full text-center bg-red-400 hover:text-gray-100 hover:bg-red-600">
{{__('Leave Study')}}
</div>
</a>
</div>
</div>
......
......@@ -11,6 +11,8 @@
@endif
</div>
</div>
@if(count($interviews) > 0)
<div class="py-4 text-center">
<a href="{{url('export/'.$study->id."/study")}}"
class="bg-red-300 hover:bg-red-400 text-black-800 font-bold py-2 px-4 rounded inline-flex items-center">
......@@ -21,6 +23,7 @@
</b-icon>
{{__('Export all the interviews')}}</a>
</div>
@endif
<interview-list :interviews="{{$interviews}}"></interview-list>
<h1 class="text-4xl font-extrabold text-blue-600 break-words my-2">{{__('Public Url List')}}</h1>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment