Commit 66efc03d authored by ZeMKI's avatar ZeMKI
Browse files

new token modal add in interview

* done another modal for adding a token during the interview
* color correction
parent 6d7e0fbc
......@@ -24,17 +24,17 @@ class Token extends Model
public static function boot()
{
parent::boot();
static::deleting(static function ($token)
{
static::deleting(static function ($token) {
$delete = true;
if ($token->studies()->count() > 0) $delete = false;
if ($delete)
{
if ($token->studies()->count() > 0) {
$delete = false;
}
if ($delete) {
File::delete($token->image_path);
$token->studies()->detach();
} else return false;
} else {
return false;
}
});
}
......@@ -45,30 +45,31 @@ class Token extends Model
*/
public static function store($tokenToSave, $study, $isInterview = false)
{
ray($tokenToSave, $study);
$imageIsPreset = ((isset($tokenToSave['ispreset']) && $tokenToSave['ispreset'])
|| (isset($tokenToSave['file']['ispreset']) && $tokenToSave['file']['ispreset']))
|| (isset($tokenToSave['image_path'])
&& strpos($tokenToSave['image_path'], 'presets') !== false);
if ($imageIsPreset)
{
if ($imageIsPreset) {
// save only preset path
$token = new self;
$token->name = $tokenToSave['name'];
if ($isInterview) $token->image_path = $tokenToSave['file']['dirname'];
else $token->image_path = isset($tokenToSave['file']) ? $tokenToSave['file'] : $tokenToSave['image_path'];
} else
{
if ($isInterview) {
$token->image_path = $tokenToSave['file'];
} else {
$token->image_path = isset($tokenToSave['file']) ? $tokenToSave['file'] : $tokenToSave['image_path'];
}
} else {
// either save new image or use the default
$thereIsImageToUpload = isset($tokenToSave['base64']) || isset($tokenToSave['fileUpload']) || isset($tokenToSave['file']['base64']);
if ($thereIsImageToUpload)
{
if($isInterview) $image = $tokenToSave['file']['base64'];
else $image = isset($tokenToSave['fileUpload']) && $tokenToSave['fileUpload'] != [] ? $tokenToSave['fileUpload']['base64'] : $tokenToSave['base64'];
} else
{
if ($thereIsImageToUpload) {
if ($isInterview) {
$image = $tokenToSave['base64'];
} else {
$image = isset($tokenToSave['fileUpload']) && $tokenToSave['fileUpload'] != [] ? $tokenToSave['fileUpload']['base64'] : $tokenToSave['base64'];
}
} else {
$image = config('utilities.sortingBasicIcon');
}
$name = $tokenToSave['name'];
......@@ -77,8 +78,7 @@ class Token extends Model
$studyPath = storage_path('app/study' . $study->id . '/tokens/');
File::isDirectory($studyPath) or File::makeDirectory($studyPath, 0775, true, true);
// create a new name if the file with the same name exist
if (file_exists($studyPath . $name . '.mtoken'))
{
if (file_exists($studyPath . $name . '.mtoken')) {
$name = now()->timestamp . $name;
}
$extension = Helper::extension($image);
......@@ -94,10 +94,16 @@ class Token extends Model
$token->name = $tokenToSave['name'];
$token->image_path = $encryptedName;
}
if ($isInterview) $token->author = 0;
else $token->author = Auth::user()->id;
if (!empty($tokenToSave['properties'])) $token->properties = json_encode($tokenToSave['properties']);
else $token->properties = '{"description":""}';
if ($isInterview) {
$token->author = 0;
} else {
$token->author = Auth::user()->id;
}
if (!empty($tokenToSave['properties'])) {
$token->properties = json_encode($tokenToSave['properties']);
} else {
$token->properties = '{"description":""}';
}
$token->save();
$token->studies()->sync($study->id);
......@@ -116,16 +122,15 @@ class Token extends Model
*/
private static function SaveNewToken($tokenToSave, $study, $isInterview, &$token)
{
$thereIsImageToUpload = isset($tokenToSave['base64']) || isset($tokenToSave['fileUpload']) || isset($tokenToSave['file']['base64']);
if ($thereIsImageToUpload)
{
if($isInterview) $image = $tokenToSave['file']['base64'];
else $image = isset($tokenToSave['fileUpload']) && $tokenToSave['fileUpload'] != [] ? $tokenToSave['fileUpload']['base64'] : $tokenToSave['base64'];
} else
{
if ($thereIsImageToUpload) {
if ($isInterview) {
$image = $tokenToSave['file']['base64'];
} else {
$image = isset($tokenToSave['fileUpload']) && $tokenToSave['fileUpload'] != [] ? $tokenToSave['fileUpload']['base64'] : $tokenToSave['base64'];
}
} else {
ray("no image to upload");
$image = config('utilities.sortingBasicIcon');
}
......@@ -150,8 +155,7 @@ class Token extends Model
public static function saveImage($image, string $studyPath, $name, $base64FirstPart, Study $newStudy, $tokenToSave, &$token): void
{
// create a new name if the file with the same name exist
if (file_exists($studyPath . $name . '.mtoken'))
{
if (file_exists($studyPath . $name . '.mtoken')) {
$name = now()->timestamp . $name;
}
$extension = Helper::extension($image);
......@@ -190,15 +194,12 @@ class Token extends Model
public static function formatForEdit($tokens)
{
$tokensCount = count($tokens);
for ($i = 0; $i < $tokensCount; $i++)
{
for ($i = 0; $i < $tokensCount; $i++) {
$tokenIsPreset = strpos($tokens[$i]['image_path'], 'presets') !== false;
if ($tokenIsPreset)
{
if ($tokenIsPreset) {
$path = $tokens[$i]['image_path'];
$tokens[$i]['image_path'] = mb_convert_encoding($path, 'HTML-ENTITIES', 'UTF-8');
} else
{
} else {
$path = storage_path('app/' . $tokens[$i]['image_path']);
$tokens[$i]['image_path'] = decrypt(file_get_contents($path));
}
......
......@@ -43,13 +43,13 @@ Vue.prototype.trans = (key) => {
Vue.use(Buefy);
Vue.use(Vuex);
Vue.use(RayPlugin, {
interceptErrors: true,
interceptErrors: false,
host: "localhost",
port: 23517,
scheme: "http",
showComponentEvents: ["created", "updated"],
showComponentEvents: ["created"],
nodeRaySettings: {
interceptConsoleLog: true,
interceptConsoleLog: false,
},
});
......
......@@ -549,7 +549,7 @@
<li @mousedown="setTokenFromPreset(index,option.dirname)" class="relative py-2 pl-3 text-gray-900 cursor-default select-none pr-9" id="option-0" role="option" tabindex="-1" v-for="(option,indexj) in preset" :key="indexj">
<div class="flex items-center">
<img :src="option.dirname" :alt="option.basename" class="flex-shrink-0 w-6 h-6 rounded-full">
<span class="ml-3 truncate"> {{ option.basename }}</span>
<span class="ml-3 truncate">{{ option.basename }}</span>
</div>
</li>
......@@ -561,7 +561,7 @@
v-model="t.fileUpload"
accept="image/*"
@input="setTokenName(index)">
<a class="px-4 py-2 font-bold text-white bg-red-500 rounded hover:bg-red-700 md:w-auto sm:w-4">
<a class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700 md:w-auto sm:w-4">
<div
class="text-center md:text-xs">
{{
......@@ -1298,8 +1298,7 @@
</template>
<script>
import ArrowLeft from 'vue-material-design-icons/ArrowLeft.vue';
import ArrowRight from 'vue-material-design-icons/ArrowRight.vue';
export default {
props: {
......@@ -1307,8 +1306,6 @@ export default {
type: Object, require: false, default: null,
},
}, components: {
ArrowRight, ArrowLeft,
}, data() {
return {
tokenhistory: 0,
......
......@@ -377,16 +377,25 @@
</div>
</div>
<div>
<label for="name" class="sr-only">Name</label>
<input
v-model="interviewee"
type="name"
name="name"
id="name"
class="block w-full p-2 m-2 border-black rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
placeholder=". . ."
/>
<div class="mt-1">
<input
v-model="interviewee"
type="name"
name="name"
id="name"
class="block w-full p-2 border-gray-500 border-solid rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
placeholder=". . ."
aria-describedby="name-description"
/>
</div>
<p
class="mt-2 text-sm text-gray-500"
id="email-description"
>
{{ trans("You can leave this field empty") }}
</p>
</div>
<div
class="mt-5 sm:mt-6 sm:grid sm:grid-cols-2 sm:gap-3 sm:grid-flow-row-dense"
>
......
import Vue from 'vue';
import Vuex from 'vuex';
import Buefy from 'buefy';
import Vue from "vue";
import Vuex from "vuex";
import Buefy from "buefy";
Vue.use(
Vuex);
Vue.use(
Buefy);
Vue.use(Vuex);
Vue.use(Buefy);
export default new Vuex.Store(
{
export default new Vuex.Store({
state: {
newinterview: {
toggleCards: false,
qsortSizeIndex: 3,
qsortDistanceIndex: 2,
center_x: 0,
center_y: 0,
bounds: {},
parentPos: 0,
imagepreset: [],
newtoken: {},
fetchtoken: false,
uploadProgress: 0,
page: 0,
sorting: 1,
sortingtotal: 1,
pagenames: [
'Pre-Sorting Questions',
'Sorting',
'Post-Sorting Questions'],
buttonnames: [
[
'',
'Sorting >'],
[
'< Questions',
'Questions >'],
[
'< Sorting',
'End Interview']],
loadedsortings: 0,
newtokenmodal: false,
selectedclassifier: {},
presortQuestions: true,
postsortQuestions: true,
sortingType: 0,
selectedToken: {}
},
newinterview: {
toggleCards: false,
qsortSizeIndex: 3,
qsortDistanceIndex: 2,
center_x: 0,
center_y: 0,
bounds: {},
parentPos: 0,
imagepreset: [],
newtoken: {},
fetchtoken: false,
uploadProgress: 0,
page: 0,
sorting: 1,
sortingtotal: 1,
pagenames: [
"Pre-Sorting Questions",
"Sorting",
"Post-Sorting Questions",
],
buttonnames: [
["", "Sorting >"],
["< Questions", "Questions >"],
["< Sorting", "End Interview"],
],
loadedsortings: 0,
newtokenmodal: false,
selectedclassifier: {},
presortQuestions: true,
postsortQuestions: true,
sortingType: 0,
selectedToken: {},
},
},
mutations: {
newinterview(
state,
interview) {
state.newinterview = interview;
},
setCenterAndBounds(state, payload) {
state.newinterview.center_x = payload.center_x
state.newinterview.center_y = payload.center_y
state.newinterview.bounds = payload.bounds
state.newinterview.parentPos = payload.parentPos
},
imagepreset(
state,
images) {
state.newinterview.imagepreset = images;
},
settoken: function (state) {
state.newinterview.newtoken.ispreset = false;
state.newinterview.newtoken.image_path = '';
let reader = new FileReader();
let file = state.newinterview.newtoken.file;
let self = this;
reader.onload = function (file) {
let im = new Image();
im.onload = function () {
var canvas = document.createElement(
'canvas'),
ctx = canvas.getContext(
'2d');
canvas.width = 100;
canvas.height = 100;
if (im.width <
100 ||
im.height <
100) {
ctx.drawImage(
im,
0,
0,
100,
100,
0,
0,
canvas.width,
canvas.height,
);
newinterview(state, interview) {
state.newinterview = interview;
},
setCenterAndBounds(state, payload) {
state.newinterview.center_x = payload.center_x;
state.newinterview.center_y = payload.center_y;
state.newinterview.bounds = payload.bounds;
state.newinterview.parentPos = payload.parentPos;
},
imagepreset(state, images) {
state.newinterview.imagepreset = images;
},
settoken: function (state) {
state.newinterview.newtoken.ispreset = false;
state.newinterview.newtoken.image_path = "";
let reader = new FileReader();
let file = state.newinterview.newtoken.file;
let self = this;
reader.onload = function (file) {
let im = new Image();
im.onload = function () {
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d");
canvas.width = 100;
canvas.height = 100;
if (im.width < 100 || im.height < 100) {
ctx.drawImage(
im,
0,
0,
100,
100,
0,
0,
canvas.width,
canvas.height
);
} else {
self.drawImageProp(
ctx,
im,
0,
0,
canvas.width,
canvas.height
);
}
let newimgUri = canvas.toDataURL("image/*").toString();
document.getElementById("newtoken").src = newimgUri;
};
im.src = file.target.result;
// create a new property in
// self.sorting.tokens[index] to save the base64
// then save the file object in .file
// to solve the error for the file object
self.sorting.tokens[index].base64 = file.target.result;
};
reader.readAsDataURL(file);
if (state.newinterview.newtoken.name === "") {
state.newinterview.newtoken.name =
state.newinterview.newtoken.file.name;
}
else {
self.drawImageProp(
ctx,
im,
0,
0,
canvas.width,
canvas.height,
);
}
let newimgUri = canvas.toDataURL(
'image/*').toString();
document.getElementById(
'newtoken').src = newimgUri;
};
im.src = file.target.result;
// create a new property in
// self.sorting.tokens[index] to save the base64
// then save the file object in .file
// to solve the error for the file object
self.sorting.tokens[index].base64 = file.target.result;
};
reader.readAsDataURL(
file);
if (state.newinterview.newtoken.name ===
'') {
state.newinterview.newtoken.name = state.newinterview.newtoken.file.name;
}
},
changeToken: function (state) {
Vue.set(
state,
'fetchtoken',
true,
);
},
setFetchToken: function (state, value) {
Vue.set(
state,
'fetchtoken',
value,
);
},
resetToken: function (state) {
state.newinterview.newtoken.file.name = '';
},
updatepage: function (state, value) {
state.newinterview.page = value;
},
updatesortingnumber: function (state, value) {
state.newinterview.sorting = value;
},
updateselectedtoken: function (state, value) {
state.newinterview.selectedToken = value
},
updateselectedclassifier: function (state, value) {
state.newinterview.selectedclassifier = value;
},
increasemaxsorting: function (state) {
state.newinterview.sortingtotal++;
},
updateloadedsorting: function (state, value) {
state.newinterview.loadedsortings = value;
},
newtokenmodal: function (state, value) {
state.newinterview.newtokenmodal = !state.newinterview.newtokenmodal;
},
aretherepresortquestion: function (state, value) {
state.newinterview.presortQuestions = value;
},
aretherepostsortquestions: function (state, value) {
state.newinterview.postsortQuestions = value;
},
typeofsorting: function (state, value) {
state.newinterview.sortingType = value;
},
updateToggleCards: function (state, value) {
state.newinterview.toggleCards = value;
},
updateqsortSizeIndex: function (state, value) {
state.newinterview.qsortSizeIndex = value;
},
updateqsortDistanceIndex: function (state, value) {
state.newinterview.qsortDistanceIndex = value;
}
},
changeToken: function (state) {
Vue.set(state, "fetchtoken", true);
},
setFetchToken: function (state, value) {
Vue.set(state, "fetchtoken", value);
},
resetToken: function (state) {
state.newinterview.newtoken.file.name = "";
},
updatepage: function (state, value) {
state.newinterview.page = value;
},
updatesortingnumber: function (state, value) {
state.newinterview.sorting = value;
},
updateselectedtoken: function (state, value) {
state.newinterview.selectedToken = value;
},
updateselectedclassifier: function (state, value) {
state.newinterview.selectedclassifier = value;
},
increasemaxsorting: function (state) {
state.newinterview.sortingtotal++;
},
updateloadedsorting: function (state, value) {
state.newinterview.loadedsortings = value;
},
newtokenmodal: function (state, value) {
state.newinterview.newtokenmodal =
!state.newinterview.newtokenmodal;
},
aretherepresortquestion: function (state, value) {
state.newinterview.presortQuestions = value;
},
aretherepostsortquestions: function (state, value) {
state.newinterview.postsortQuestions = value;
},
typeofsorting: function (state, value) {
state.newinterview.sortingType = value;
},
updateToggleCards: function (state, value) {
state.newinterview.toggleCards = value;
},
updateqsortSizeIndex: function (state, value) {
state.newinterview.qsortSizeIndex = value;
},
updateqsortDistanceIndex: function (state, value) {
state.newinterview.qsortDistanceIndex = value;
},
},
actions: {
async setimagepreset(context) {
axios.post(
'../api/v1/getpresettokenimages').then(
response => {
context.commit(
'imagepreset',
response.data.presetimages,
async setimagepreset(context) {
axios
.post("../api/v1/getpresettokenimages")
.then((response) => {