Commit 70a73f03 authored by ZeMKI's avatar ZeMKI
Browse files

Layout update - bugfixing - code cleanup

* Massive code refactor
* fixes #17
* home layout changed
* tailwind installed
parent b0dcb3c5
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="MariaDB - mesort@localhost" uuid="c493b4ee-01fe-4081-88a8-5e0fb9691414">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306/mesort</jdbc-url>
<driver-properties>
<property name="autoReconnect" value="true" />
<property name="zeroDateTimeBehavior" value="convertToNull" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
</driver-properties>
</data-source>
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="belli">
<words>
<w>screenshot</w>
</words>
</dictionary>
</component>
\ No newline at end of file
......@@ -30,6 +30,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/jakub-onderka/php-console-color" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jakub-onderka/php-console-highlighter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jean85/pretty-package-versions" />
<excludeFolder url="file://$MODULE_DIR$/vendor/justinrainbow/json-schema" />
<excludeFolder url="file://$MODULE_DIR$/vendor/kkszymanowski/traitor" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/framework" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/telescope" />
......@@ -94,12 +95,15 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/resource-operations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/seld/jsonlint" />
<excludeFolder url="file://$MODULE_DIR$/vendor/seld/phar-utils" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sensiolabs/security-checker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/slam/php-cs-fixer-extensions" />
<excludeFolder url="file://$MODULE_DIR$/vendor/slevomat/coding-standard" />
<excludeFolder url="file://$MODULE_DIR$/vendor/squizlabs/php_codesniffer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swiftmailer/swiftmailer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/config" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/contracts" />
......@@ -107,10 +111,14 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/debug" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/dependency-injection" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/filesystem" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/finder" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/mime" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/options-resolver" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-iconv" />
......@@ -118,10 +126,13 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php70" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php73" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/process" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/routing" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/stopwatch" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-dumper" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-exporter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/yaml" />
......
......@@ -133,9 +133,20 @@
<path value="$PROJECT_DIR$/vendor/symfony/cache" />
<path value="$PROJECT_DIR$/vendor/symfony/filesystem" />
<path value="$PROJECT_DIR$/vendor/symfony/options-resolver" />
<path value="$PROJECT_DIR$/vendor/justinrainbow/json-schema" />
<path value="$PROJECT_DIR$/vendor/seld/jsonlint" />
<path value="$PROJECT_DIR$/vendor/seld/phar-utils" />
<path value="$PROJECT_DIR$/vendor/symfony/cache-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/http-client" />
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/mime" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
<component name="PhpProjectSharedConfiguration" php_language_level="7.3" />
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings load_method="CUSTOM_LOADER" configuration_file_path="$PROJECT_DIR$/phpunit.xml" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" use_configuration_file="true" />
......
......@@ -45,22 +45,22 @@ class CreateUserCommand extends Command
public function handle()
{
$user = new User;
$email = $this->ask('Enter email');
$password = $this->secret('Enter password');
$this->info('2 -> Supervisor');
$this->info('3 -> Researcher');
$role = $this->choice('User role?',[2,3]);
$role = $this->choice('User role?', [2, 3]);
if($this->store($role,$email,$password)) return true;
else return false;
if ($this->store($role, $email, $password))
return true;
else
return false;
}
public function store($roleId,$email,$password)
public function store($roleId, $email, $password)
{
$role = Role::where('id', $roleId)->first();
......@@ -69,11 +69,11 @@ class CreateUserCommand extends Command
$user->password = bcrypt($password);
$user->save();
$user->attachRole($role);
$createstudypermission = Permission::where('name', 'create-studies')
$createStudyPermission = Permission::where('name', 'create-studies')
->first();
$user->supervised_by = $user->id;
$user->save();
$user->attachPermissions([$createstudypermission]);
$user->attachPermissions([$createStudyPermission]);
return true;
}
......
......@@ -38,38 +38,36 @@ class DeleteClosedStudies extends Command
public function handle()
{
$headers = ['Study Name', 'made by'];
$studiesAndCreator = \App\Study::join('users','user_id','=','users.id')->select('studies.name', 'users.email')->get()->toArray();
$studiesAndCreator = \App\Study::join('users', 'user_id', '=', 'users.id')->select('studies.name', 'users.email')->get()->toArray();
$this->table($headers, $studiesAndCreator);
$headers = ['Study Id','Study Name'];
$studies = \App\Study::select('studies.id','studies.name')->get()->toArray();
$headers = ['Study Id', 'Study Name'];
$studies = \App\Study::select('studies.id', 'studies.name')->get()->toArray();
$this->table($headers, $studies);
$studiesId = \App\Study::pluck('id')->toArray();
array_unshift($studiesId,0);
array_unshift($studiesId, 0);
$this->warn("Press 0 to delete nothing");
$id = $this->choice('Which study you want to delete??',$studiesId,0);
$id = $this->choice('Which study you want to delete??', $studiesId, 0);
$study = \App\Study::find($id);
if(!$study){
if (!$study) {
$this->warn("study not found or exited with 0");
}else if($study->interviews->count() > 0){
} else if ($study->interviews->count() > 0 && $this->confirm("THIS STUDY HAS INTERVIEWS, YOU WILL DELETE THEM. ARE YOU SURE?", false)) {
if($this->confirm("THIS STUDY HAS INTERVIEWS, YOU WILL DELETE THEM. ARE YOU SURE?",false)){
foreach ($study->interviews as $i){
$i->answers()->detach();
$i->answers()->delete();
$i->tokens()->detach();
$i->tokens()->delete();
$i->delete();
foreach ($study->interviews as $interview) {
$interview->answers()->detach();
$interview->answers()->delete();
$interview->tokens()->detach();
$interview->tokens()->delete();
$interview->delete();
}
$study->interviews()->delete();
$study->delete();
$this->info("study deleted!");
}
}
......
......@@ -2,6 +2,8 @@
namespace App\Helpers;
use Exception;
class Helper
{
......@@ -10,7 +12,7 @@ class Helper
* @param $length
* @param string $keyspace
* @return string
* @throws \Exception
* @throws Exception
*/
public static function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$%()=-*.,')
{
......@@ -22,32 +24,6 @@ class Helper
return implode('', $pieces);
}
/**
* Save and encrypt an image with custom extension
* @param [type] $entity [description]
* @param [type] $name [description]
* @param [type] $type [description]
* @return String path where the image is saved
*/
public static function encrypt_image($entity, $name, $image, $type)
{
$extension = $this->extension($image);
$name = $t['name'];
$arr = explode(",", $t['base64'], 2);
$base64firstpart = $arr[0];
// open file a image resource
\Image::make($image)->fit(100, 100)->save(storage_path('app/tokens/'.$name));
$path = storage_path('app/tokens/'.$name);
$ext = pathinfo($path, PATHINFO_EXTENSION);
$encryptedContent = encrypt($base64firstpart.",".base64_encode(file_get_contents($path)));
// Store the encrypted Content
Storage::put('tokens/'.$name.'.mtoken', $encryptedContent);
File::delete($path);
}
/**
* return extension of base64 image
......
......@@ -2,69 +2,58 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Telescope\Telescope;
use App\User;
use App\Study;
use App\Role;
use App\Permission;
use App\Interview;
use GuzzleHttp;
use App\Permission;
use App\Role;
use App\Study;
use App\User;
use Illuminate\Http\Request;
class AdminController extends Controller
{
/**
* show dashboard
* @return [type] [description]
*/
public function index()
{
$client = new GuzzleHttp\Client(['base_uri' => url()->current(),'X-CSRF-TOKEN' => csrf_token(),'verify'=> false,'user'=> auth()->user()]);
// $response = $client->request('POST', 'telescope/telescope-api/exceptions');
// $exceptions = json_decode($response->getBody()->getContents())->entries;
// gather data for the inital panel
/**
* show dashboard
* @return [type] [description]
*/
public function index()
{
// gather data for the inital panel
$data['user'] = auth()->user();
$data['usercount'] = User::all()->count();
$data['studiescount'] = Study::all()->count();
$data['interviewcount'] = Interview::all()->count();
$data['exceptions'] = [];
return view('admin.dashboard', $data);
// gather data for the initial panel
$data['user'] = auth()->user();
$data['usercount'] = User::all()->count();
$data['studiescount'] = Study::all()->count();
$data['interviewcount'] = Interview::all()->count();
$data['exceptions'] = [];
}
return view('admin.dashboard', $data);
public function supervisorindex()
{
}
return view('admin.supervisor');
public function supervisorIndex()
{
return view('admin.supervisor');
}
}
public function addSupervisor(Request $request)
{
$role = Role::where('id', $request->role)->first();
$user = new User();
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->save();
$user->attachRole($role);
$createStudyPermission = Permission::where('name', 'create-studies')
->first()->toArray();
$user->supervised_by = $user->id;
$user->save();
$user->attachPermissions($createStudyPermission);
public function addSupervisor(Request $request)
{
$role = Role::where('id', $request->role)->first();
$user = new User();
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->save();
$user->attachRole($role);
$createStudyPermission = Permission::where('name', 'create-studies')
->first()->toArray();
$user->supervised_by = $user->id;
$user->save();
$user->attachPermissions($createStudyPermission);
return view('admin.supervisor',["message" => "sup added yo"]);
}
return view('admin.supervisor', ["message" => "sup added yo"]);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Symfony\Component\Process\Process;
class DeployController extends Controller
{
public function deploy(Request $request)
{
public function deploy(Request $request)
{
$githubPayload = $request->getContent();
$githubHash = $request->header('X-Gitlab-Token');
$localToken = config('app.deploy_secret');
if ($githubHash == $localToken) {
$root_path = base_path();
$process = new Process('cd ' . $root_path . '; ./deploy.sh');
$process->run(function ($type, $buffer) {
echo $buffer;
});
}else{
echo 'problems!';
}
}
$githubHash = $request->header('X-Gitlab-Token');
$localToken = config('app.deploy_secret');
if ($githubHash === $localToken) {
$root_path = base_path();
$process = new Process('cd ' . $root_path . '; ./deploy.sh');
$process->run(function ($buffer) {
echo $buffer;
});
} else {
echo 'problems!';
}
}
}
......@@ -43,6 +43,6 @@ class HomeController extends Controller
\Session::put('locale', $locale);
return redirect()->back();
return redirect()->back();
}
}
......@@ -2,17 +2,20 @@
namespace App\Http\Controllers;
use App\Permission;
use Illuminate\Http\Request;
use App\Answer;
use App\Interview;
use App\Permission;
use App\Question;
use App\Answer;
use App\Study;
use App\User;
use Auth;
use DB;
use Storage;
use File;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Storage;
class InterviewController extends Controller
{
......@@ -30,81 +33,70 @@ class InterviewController extends Controller
$data['study'] = $study;
$data['questions'] = $study->questions;
$data['sorting'] = $study->sortings[0];
$data['author'] = User::where('id',$author)->first();
$data['author'] = User::where('id', $author)->first();
/** EXTRACT METHOD FORMATQUETSTIONSANSWERS */
foreach ($data['questions'] as $q) {
$q['available_answers'] = $q->availableAnswers();
$q['answers'] = $q->answers()->having('pivot_interview_id', '=', $interview->id)->get();
}
/** EXTRACT METHOD GETINFOCIRCLE */
$pieces = explode("||", $study->sortings[0]->pivot->details);
$circles = strstr($pieces[0], '|');
$circles = substr($circles, 1);
$data['circles'] = $circles;
/** EXTRACT METHOD GETIMAGE */
$type = pathinfo($interview->sorting_screenshot, PATHINFO_EXTENSION);
$imagedata = decrypt(file_get_contents($interview->sorting_screenshot));
$data['interview']['sorting_screenshot'] = $imagedata;
$this->formatQuestionsAnswers($interview, $data);
$this->getSortingInfo($study, $data);
$this->getSortingImage($interview, $data);
return view('interview.view', $data);
}
/**
* SHOW THE CREATE INTERVIEW PAGE
* gather the data and format them in a correct way for the frontend
* @param Request $request [description]
* @return [type] [description]
*
* @param Request $request
* @return Factory|View
* @throws AuthorizationException
*/
public function create(Request $request)
{
$this->authorize([Interview::class,$request->input('study')]);
$this->authorize([Interview::class, $request->input('study')]);
/** Extract method FORMATQUESTIONSANSWERS */
$query ='
select distinct qid, q, d,
$query = '
select distinct qid, q, type,
GROUP_CONCAT(answer SEPARATOR ",") as answer,
GROUP_CONCAT(answers.id SEPARATOR ",") as answerids
from (
Select distinct questions.id as qid, questions.question as q, questions.detail as d
Select distinct questions.id as qid, questions.question as q, questions.detail as type
from questions
where `study_id` = '.$request->input('study').'
where `study_id` = ' . $request->input('study') . '
) as qtable
left join `answers` on qid = `answers`.`question_id`
group by qid,q,d';
group by qid,q,type';
$questions = DB::select(DB::raw($query));
$returnquestions['presort'] = [];
$returnquestions['postsort'] = [];
foreach ($questions as $q) {
$q->answer = json_decode("[".$q->answer."]");
$q->answer['ids'] = explode(',', $q->answerids);
if ($q->d == 'presort') {
array_push($returnquestions['presort'], $q);
$returnQuestions['presort'] = [];
$returnQuestions['postsort'] = [];
foreach ($questions as $question) {
$question->answer = json_decode("[" . $question->answer . "]");
$question->answer['ids'] = explode(',', $question->answerids);
if ($question->type === 'presort') {
array_push($returnQuestions['presort'], $question);
}
if ($q->d == 'postsort') {
array_push($returnquestions['postsort'], $q);
if ($question->type === 'postsort') {
array_push($returnQuestions['postsort'], $question);
}
}
$data['questions'] = $returnquestions;
$data['questions'] = $returnQuestions;
$data['study'] = Study::where('id', '=', $request->input('study'))->with('sortings')->first();
$data['interviewed'] = htmlspecialchars($request->input('interviewed') == "" ? "Name not provided" : $request->input('interviewed'));
$data['interviewed'] = htmlspecialchars(empty($request->input('interviewed')) ? "Name not provided" : $request->input('interviewed'));
$data['sorting'] = $data['study']->sorting[0];
$data['tokens'] = $data['study']->available_tokens;
/** extract method GETTOKENS */
for ($i=0; $i < count($data['tokens']); $i++) {
$TokensCount = count($data['tokens']);
for ($i = 0; $i < $TokensCount; $i++) {
if (strpos($data['tokens'][$i]['image_path'], 'presets') !== false) {
$path = $data['tokens'][$i]['image_path'];
$data['tokens'][$i]['image_path'] = mb_convert_encoding($path,'HTML-ENTITIES', "UTF-8");
}else{
$path = storage_path('app/'.$data['tokens'][$i]['image_path']);
$data['tokens'][$i]['image_path'] = mb_convert_encoding($path, 'HTML-ENTITIES', "UTF-8");
} else {
$path = storage_path('app/' . $data['tokens'][$i]['image_path']);
$data['tokens'][$i]['image_path'] = decrypt(file_get_contents($path));
}
......@@ -120,98 +112,127 @@ class InterviewController extends Controller
public function extension($uri)
{
$img = explode(',', $uri);
$ini =substr($img[0], 11);
$ini = substr($img[0], 11);
$type = explode(';', $ini);
return $type[0];
}
public function store(Request $request)
{
$interview = new Interview;
$study = Study::where('id', '=', $request->input('study'))->first();
$interview->study_id = $study->id;
$interview->author = Auth::user()->id;
$interview->interviewed = $request->input('interviewed');
$this->storeSortingScreenshot($request, $name);
// save screenshot - EXTRACT METHOD SAVEENCRYPTIMAGE
$image = $request->input('sortingscreenshot');
$name = "interview_".$request->input('time_start');
$arr = explode(",", $request->input('sortingscreenshot'), 2);
$base64firstpart = $arr[0];
$extension = $this->extension($request->input('sortingscreenshot'));
$path = storage_path('app/screenshots/'.$name.".".$extension);
// open file a image resource
\Image::make($image)->save($path);
$interview->sorting_screenshot = storage_path('app/screenshots/'.$name.'.mscreenshot');
$path = storage_path('app/screenshots/'.$name.".".$extension);
$encryptedContent = encrypt($base64firstpart.",".base64_encode(file_get_contents($path)));
// Store the encrypted Content
Storage::put('screenshots/'.$name.'.mscreenshot', $encryptedContent);
File::delete($path);
$interview->sorting_screenshot = storage_path('app/screenshots/' . $name . '.mscreenshot');