Compare commits
No commits in common. "023e1049f78d8d1c82aabbf2c7cc1d4835e4bb42" and "819dc9e876d1bc0d67640592ee12179dc2315637" have entirely different histories.
023e1049f7
...
819dc9e876
|
@ -1 +0,0 @@
|
|||
_
|
|
@ -1,100 +0,0 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
# Function to display errors
|
||||
display_errors() {
|
||||
local errors="$1"
|
||||
echo "Errors detected:"
|
||||
echo "---------------------------------------"
|
||||
echo "$errors"
|
||||
echo "---------------------------------------"
|
||||
}
|
||||
|
||||
# Get the list of staged files
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(php|js|css|jsx|ts|tsx)$')
|
||||
|
||||
# If there are no staged files, exit
|
||||
if [ -z "$STAGED_FILES" ]; then
|
||||
echo "No files staged for commit."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Initialize error flags
|
||||
ESLINT_ERRORS=""
|
||||
PHP_ERRORS=0
|
||||
|
||||
# Function to run ESLint and Prettier on JavaScript files
|
||||
run_js_tools() {
|
||||
local files="$1"
|
||||
if [ -n "$files" ]; then
|
||||
echo "Running ESLint..."
|
||||
for FILE in $files; do
|
||||
ESLINT_OUTPUT=$(npx eslint "$FILE" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
display_errors "$ESLINT_OUTPUT"
|
||||
ESLINT_ERRORS=1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Running Prettier..."
|
||||
for FILE in $files; do
|
||||
npx prettier --write "$FILE"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run PHP tools
|
||||
run_php_tools() {
|
||||
local files="$1"
|
||||
if [ -n "$files" ]; then
|
||||
echo "Checking PHP syntax errors..."
|
||||
SYNTAX_ERRORS=0
|
||||
for FILE in $files; do
|
||||
php -l "$FILE"
|
||||
if [ $? -ne 0 ]; then
|
||||
SYNTAX_ERRORS=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $SYNTAX_ERRORS -ne 0 ]; then
|
||||
PHP_ERRORS=1
|
||||
echo "Syntax errors detected in PHP files."
|
||||
fi
|
||||
|
||||
echo "Running PHPCBF..."
|
||||
for FILE in $files; do
|
||||
/home/aissel/.config/composer/vendor/bin/phpcbf --standard=/var/www/html/google_forms/phpcs.xml "$FILE" || true
|
||||
done
|
||||
|
||||
echo "Running PHP CS Fixer..."
|
||||
for FILE in $files; do
|
||||
/home/aissel/.config/composer/vendor/bin/php-cs-fixer fix "$FILE"
|
||||
done
|
||||
|
||||
echo "Running PHPCS..."
|
||||
for FILE in $files; do
|
||||
PHPCS_OUTPUT=$(/home/aissel/.config/composer/vendor/bin/phpcs --standard=/var/www/html/google_forms/phpcs.xml "$FILE" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
display_errors "$PHPCS_OUTPUT"
|
||||
PHP_ERRORS=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Run tools based on file types
|
||||
run_js_tools "$(echo "$STAGED_FILES" | grep -E '\.(js|jsx|ts|tsx)$')"
|
||||
run_php_tools "$(echo "$STAGED_FILES" | grep '\.php$')"
|
||||
|
||||
# Add the fixed files back to the staging area
|
||||
for FILE in $STAGED_FILES; do
|
||||
git add "$FILE"
|
||||
done
|
||||
|
||||
# Exit with error code if there were any errors
|
||||
if [ $PHP_ERRORS -ne 0 ] || [ $ESLINT_ERRORS -eq 1 ]; then
|
||||
echo "Pre-commit checks failed. Please fix the errors before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Pre-commit checks completed."
|
|
@ -1,25 +1,20 @@
|
|||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
namespace application\controllers;
|
||||
class Form extends CI_Controller {
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
// use application\models\Form_model;
|
||||
|
||||
class Form extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->model('Form_model');
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
|
||||
public function submit() {
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
// If not logged in, redirect to login page
|
||||
redirect('users/login');
|
||||
}$form_data = json_decode($this->input->raw_input_stream, true);
|
||||
$this->load->model('Form_model');
|
||||
}
|
||||
$form_data = json_decode($this->input->raw_input_stream, true);
|
||||
|
||||
if ($this->Form_model->save_form($form_data)) {
|
||||
$response = array('status' => 'success', 'message' => 'Form submitted successfully.');
|
||||
} else {
|
||||
|
@ -28,11 +23,14 @@ class Form extends CI_Controller
|
|||
|
||||
echo json_encode($response);
|
||||
}
|
||||
public function view($form_id)
|
||||
{
|
||||
|
||||
public function view($form_id) {
|
||||
$data['title'] = $this->Form_model->get_form_title($form_id);
|
||||
|
||||
if ($data['title'] === null) {
|
||||
show_404(); // Show 404 if form_id is invalid
|
||||
}$this->load->view('templates/forms_ui', $data);
|
||||
}
|
||||
|
||||
$this->load->view('templates/forms_ui',$data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Forms extends CI_Controller
|
||||
|
@ -10,9 +9,6 @@ class Forms extends CI_Controller
|
|||
// If not logged in, redirect to login page
|
||||
redirect('users/login');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load the model that handles the form data
|
||||
$this->load->model('preview_model');
|
||||
|
||||
|
@ -31,25 +27,26 @@ class Forms extends CI_Controller
|
|||
$data['form'] = $form;
|
||||
$data['questions'] = $questions;
|
||||
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('templates/header');
|
||||
|
||||
$this->load->view('form_preview', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function response_preview($form_id)
|
||||
{
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
// If not logged in, redirect to login page with form_id as a parameter
|
||||
redirect('users/login/' . $form_id);
|
||||
}
|
||||
|
||||
|
||||
// Load the model that handles the form data
|
||||
$this->load->model('preview_model');
|
||||
|
||||
|
||||
// Fetch the form details
|
||||
$form = $this->preview_model->get_form($form_id);
|
||||
|
||||
|
||||
// Check if the form is responsive
|
||||
if ($form->is_responsive == 0) {
|
||||
// Pass a message to the view
|
||||
|
@ -57,49 +54,49 @@ class Forms extends CI_Controller
|
|||
$this->load->view('response_submit', $data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Fetch the questions for the form
|
||||
$questions = $this->preview_model->get_questions($form_id);
|
||||
|
||||
|
||||
// Fetch the options for each question
|
||||
foreach ($questions as &$question) {
|
||||
$question->options = $this->preview_model->get_options($question->id);
|
||||
}
|
||||
|
||||
|
||||
// Pass the data to the view
|
||||
$data['form'] = $form;
|
||||
$data['questions'] = $questions;
|
||||
|
||||
|
||||
$this->load->view('response_submit', $data);
|
||||
}
|
||||
|
||||
public function preview_back($form_id)
|
||||
{
|
||||
|
||||
public function preview_back($form_id) {
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
// If not logged in, redirect to login page
|
||||
redirect('users/login');
|
||||
}
|
||||
|
||||
|
||||
// Load the model that handles the form data
|
||||
$this->load->model('preview_model');
|
||||
|
||||
|
||||
// Fetch the form details
|
||||
$form = $this->preview_model->get_form($form_id);
|
||||
|
||||
|
||||
// Fetch the questions for the form including 'is_required'
|
||||
$questions = $this->preview_model->get_questions($form_id);
|
||||
|
||||
|
||||
// Fetch the options for each question
|
||||
foreach ($questions as &$question) {
|
||||
$question->options = $this->preview_model->get_options($question->id);
|
||||
}
|
||||
// / Pass the data to the view
|
||||
|
||||
// Pass the data to the view
|
||||
$data['form'] = $form;
|
||||
$data['questions'] = $questions;
|
||||
|
||||
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('form_preview_back', $data);
|
||||
$this->load->view('templates/footer');
|
||||
// $this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
namespace application\controllers;
|
||||
class Welcome extends CI_Controller {
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Welcome extends CI_Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('welcome_message');
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('welcome_message');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,34 @@
|
|||
$(document).ready(function () {
|
||||
let index = 1
|
||||
let activeSection = null
|
||||
function addOption(type, container) {
|
||||
let optionHtml
|
||||
$(document).ready(function() {
|
||||
let index = 1;
|
||||
let activeSection = null;
|
||||
|
||||
if (type === 'multiple-choice' || type === 'checkboxes') {
|
||||
optionHtml = `
|
||||
function addOption(type, container) {
|
||||
let optionHtml;
|
||||
if (type === 'multiple-choice' || type === 'checkboxes') {
|
||||
optionHtml = `
|
||||
<div class="option">
|
||||
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
|
||||
<input type="text" class="form-control option-label">
|
||||
|
||||
<span class="delete-option-icon">×</span>
|
||||
</div>
|
||||
`
|
||||
} else if (type === 'dropdown') {
|
||||
optionHtml = `
|
||||
`;
|
||||
} else if (type === 'dropdown') {
|
||||
optionHtml = `
|
||||
<div class="option">
|
||||
<input type="text" class="form-control option-label">
|
||||
<span class="delete-option-icon">×</span>
|
||||
</div>
|
||||
`
|
||||
`;
|
||||
}
|
||||
container.append(optionHtml);
|
||||
}
|
||||
container.append(optionHtml)
|
||||
}
|
||||
|
||||
function createFormSection() {
|
||||
let newSection = `
|
||||
function createFormSection() {
|
||||
let newSection = `
|
||||
<div class="form-section" data-index="${index}">
|
||||
<div class="header-row">
|
||||
${index === 1 ? '<div class="violet-border"></div>' : ''}
|
||||
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
|
||||
<div class="header-row">
|
||||
${index === 1 ? '<div class="violet-border"></div>' : ''}
|
||||
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
|
||||
<select class="custom-select">
|
||||
<option value="short-answer">Short Answer</option>
|
||||
<option value="paragraph">Paragraph</option>
|
||||
|
@ -45,58 +44,50 @@ $(document).ready(function () {
|
|||
</div>
|
||||
<div class="options-container"></div>
|
||||
</div>
|
||||
`
|
||||
$('#form-container').append(newSection)
|
||||
index++
|
||||
`;
|
||||
$('#form-container').append(newSection);
|
||||
index++;
|
||||
|
||||
positionAddSectionButton()
|
||||
}
|
||||
|
||||
function positionAddSectionButton() {
|
||||
if (activeSection) {
|
||||
let position = activeSection.position()
|
||||
let buttonWidth = $('#add-section-btn').outerWidth()
|
||||
let buttonHeight = $('#add-section-btn').outerHeight()
|
||||
|
||||
$('#add-section-btn').css({
|
||||
position: 'absolute',
|
||||
left: position.left - buttonWidth - 47 + 'px',
|
||||
top:
|
||||
position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px',
|
||||
})
|
||||
positionAddSectionButton();
|
||||
}
|
||||
}
|
||||
|
||||
$('#add-section-btn').on('click', function () {
|
||||
createFormSection()
|
||||
$('.form-section').removeClass('active')
|
||||
activeSection = $('.form-section').last()
|
||||
activeSection.addClass('active')
|
||||
positionAddSectionButton()
|
||||
})
|
||||
function positionAddSectionButton() {
|
||||
if (activeSection) {
|
||||
let position = activeSection.position();
|
||||
let buttonWidth = $('#add-section-btn').outerWidth();
|
||||
let buttonHeight = $('#add-section-btn').outerHeight();
|
||||
|
||||
$(document).on('change', '.custom-select', function () {
|
||||
let type = $(this).val()
|
||||
let container = $(this).closest('.form-section').find('.options-container')
|
||||
container.empty()
|
||||
|
||||
$(this).closest('.form-section').find('.add-option-btn').remove()
|
||||
|
||||
if (type === 'short-answer') {
|
||||
container.append(
|
||||
'<input type="text" class="form-control" disabled placeholder="Short answer text">'
|
||||
)
|
||||
} else if (type === 'paragraph') {
|
||||
container.append(
|
||||
'<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>'
|
||||
)
|
||||
} else {
|
||||
addOption(type, container)
|
||||
$(this)
|
||||
.closest('.form-section')
|
||||
.append(
|
||||
'<button class="btn btn-secondary add-option-btn">Add Option</button>'
|
||||
)
|
||||
$('#add-section-btn').css({
|
||||
position: 'absolute',
|
||||
left: position.left - buttonWidth - 47 + 'px',
|
||||
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$('#add-section-btn').on('click', function() {
|
||||
createFormSection();
|
||||
$('.form-section').removeClass('active');
|
||||
activeSection = $('.form-section').last();
|
||||
activeSection.addClass('active');
|
||||
positionAddSectionButton();
|
||||
});
|
||||
|
||||
$(document).on('change', '.custom-select', function() {
|
||||
let type = $(this).val();
|
||||
let container = $(this).closest('.form-section').find('.options-container');
|
||||
container.empty();
|
||||
|
||||
$(this).closest('.form-section').find('.add-option-btn').remove();
|
||||
|
||||
if (type === 'short-answer') {
|
||||
container.append('<input type="text" class="form-control" disabled placeholder="Short answer text">');
|
||||
} else if (type === 'paragraph') {
|
||||
container.append('<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>');
|
||||
} else {
|
||||
addOption(type, container);
|
||||
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
29
package.json
29
package.json
|
@ -6,22 +6,21 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prepare": "husky install",
|
||||
"lint": "eslint src --ext .js,.jsx --report-unused-disable-directives",
|
||||
"lint-php": "phpcs --standard=PSR12 && phpcbf --standard=PSR12 && php-cs-fixer fix",
|
||||
"format": "prettier --write"
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "phpcbf && eslint . --fix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.aissel.com/RameshT/google_forms.git"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
||||
"prettier --write"
|
||||
"*.php": [
|
||||
"phpcbf",
|
||||
"git add"
|
||||
],
|
||||
"**/*.php": [
|
||||
"phpcs --standard=PSR12",
|
||||
"phpcbf --standard=PSR12",
|
||||
"php-cs-fixer fix"
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"keywords": [],
|
||||
|
@ -29,14 +28,10 @@
|
|||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.8.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-html": "^8.1.1",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"globals": "^15.9.0",
|
||||
"husky": "^6.0.0",
|
||||
"lint-staged": "^15.2.7",
|
||||
"prettier": "^3.3.3"
|
||||
"eslint": "^9.8.0",
|
||||
"globals": "^15.8.0",
|
||||
"husky": "^8.0.0",
|
||||
"lint-staged": "^15.2.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-escapes": "^7.0.0",
|
||||
|
|
14
phpcs.xml
14
phpcs.xml
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="Custom Ruleset">
|
||||
<description>Custom ruleset excluding specific rules.</description>
|
||||
|
||||
<!-- PSR-12 rules -->
|
||||
<rule ref="PSR12"/>
|
||||
|
||||
<!-- Exclude the specific rule about side effects -->
|
||||
<rule ref="PSR1.Files.SideEffects">
|
||||
<exclude name="PSR1.Files.SideEffects"/>
|
||||
</rule>
|
||||
|
||||
<!-- Add any other rules or exclusions as needed -->
|
||||
</ruleset>
|
|
@ -1,51 +0,0 @@
|
|||
{
|
||||
"workbench.colorTheme": "Dark Chai",
|
||||
"workbench.editor.enablePreview": false,
|
||||
"files.autoSave": "afterDelay",
|
||||
"git.enableSmartCommit": true,
|
||||
"git.confirmSync": false,
|
||||
|
||||
// PHP_CodeSniffer configuration
|
||||
"phpcs.enable": true,
|
||||
"phpcs.executablePath": "/home/aissel/.config/composer/vendor/bin/phpcs",
|
||||
"phpcs.standard": "PSR12",
|
||||
|
||||
// PHP Code Beautifier and Fixer (PHPCBF) configuration
|
||||
"phpcbf.enable": true,
|
||||
"phpcbf.executablePath": "/home/aissel/.config/composer/vendor/bin/phpcbf",
|
||||
|
||||
// PHP CS Fixer configuration
|
||||
"php-cs-fixer.executablePath": "/home/aissel/.config/composer/vendor/bin/php-cs-fixer",
|
||||
"php-cs-fixer.executablePathWindows": "",
|
||||
"php-cs-fixer.onsave": true,
|
||||
"php-cs-fixer.rules": "@PSR12",
|
||||
"php-cs-fixer.config": ".php-cs-fixer.php;.php-cs-fixer.dist.php;.php_cs;.php_cs.dist",
|
||||
"php-cs-fixer.allowRisky": false,
|
||||
"php-cs-fixer.pathMode": "override",
|
||||
"php-cs-fixer.ignorePHPVersion": false,
|
||||
"php-cs-fixer.exclude": [],
|
||||
"php-cs-fixer.autoFixByBracket": true,
|
||||
"php-cs-fixer.autoFixBySemicolon": true,
|
||||
"php-cs-fixer.formatHtml": true,
|
||||
"php-cs-fixer.documentFormattingProvider": true,
|
||||
// "php-cs-fixer.setParallel": true,
|
||||
|
||||
// Format on save for PHP files
|
||||
"editor.formatOnSave": true,
|
||||
"[php]": {
|
||||
"editor.defaultFormatter": "junstyle.php-cs-fixer"
|
||||
},
|
||||
|
||||
// Additional settings
|
||||
"settingsSync.ignoredSettings": [],
|
||||
"json.schemas": [
|
||||
|
||||
|
||||
|
||||
],
|
||||
"workbench.settings.applyToAllProfiles": [
|
||||
],
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue