Compare commits

...

35 Commits

Author SHA1 Message Date
RameshT 023e1049f7 Your commit message 2024-08-08 11:42:40 +05:30
RameshT 6db7f1b834 Test Husky pre-commit hook. 2024-08-07 15:01:43 +05:30
RameshT a921ddb630 Test Husky pre-commit hook. 2024-08-07 14:58:43 +05:30
RameshT fc5965aa24 Test Husky pre-commit hook. 2024-08-07 14:55:37 +05:30
RameshT 91405ec4ed Test Husky pre-commit hook. 2024-08-07 12:47:32 +05:30
RameshT bd469fb65c Test Husky pre-commit hook. 2024-08-07 12:24:13 +05:30
RameshT 917f18bf0c Test Husky pre-commit hook. 2024-08-07 11:48:44 +05:30
RameshT ad5889dd4e Test Husky pre-commit hook. 2024-08-06 17:15:44 +05:30
RameshT f466df90a3 Test Husky pre-commit hook. 2024-08-06 16:08:01 +05:30
RameshT d513434913 Test Husky pre-commit hook. 2024-08-06 15:31:25 +05:30
RameshT 61e4b64d91 Test Husky pre-commit hook. 2024-08-06 14:54:05 +05:30
RameshT 83785ef3c6 Test Husky pre-commit hook. 2024-08-06 14:52:27 +05:30
RameshT 70036952b4 Test Husky pre-commit hook. 2024-08-06 14:50:56 +05:30
RameshT f31bf6e2d2 Test Husky pre-commit hook. 2024-08-06 14:47:03 +05:30
RameshT 376e1d0344 Test Husky pre-commit hook. 2024-08-06 14:38:17 +05:30
RameshT 668d8938ce Test Husky pre-commit hook. 2024-08-06 14:37:12 +05:30
RameshT 83d9c88539 Test Husky pre-commit hook. 2024-08-06 14:35:59 +05:30
RameshT 00636ea29a Test Husky pre-commit hook. 2024-08-06 14:34:03 +05:30
RameshT b76a107076 Test Husky pre-commit hook. 2024-08-06 10:00:53 +05:30
RameshT c8962b3f16 Test Husky pre-commit hook. 2024-08-05 16:52:16 +05:30
RameshT a914926216 Test Husky pre-commit hook. 2024-08-05 16:32:30 +05:30
RameshT 31bce137e3 Test Husky pre-commit hook. 2024-08-05 15:49:43 +05:30
RameshT 9d10e9476d Test Husky pre-commit hook. 2024-08-05 14:05:05 +05:30
RameshT 8771b7b19b Test Husky pre-commit hook. 2024-08-05 13:06:41 +05:30
RameshT c90f3bbab1 Test Husky pre-commit hook. 2024-08-05 12:53:53 +05:30
RameshT 589dbc74ab Test Husky pre-commit hook. 2024-08-05 11:28:57 +05:30
RameshT e2afbaade8 Test Husky pre-commit hook. 2024-08-05 11:23:36 +05:30
RameshT 744d16f1e0 Test Husky pre-commit hook. 2024-08-05 10:44:51 +05:30
RameshT 7d745b6fa7 Test Husky pre-commit hook. 2024-08-05 10:30:08 +05:30
RameshT 7b09cba3fb Test Husky pre-commit hook. 2024-08-05 10:28:48 +05:30
RameshT ff26499574 Test Husky pre-commit hook. 2024-08-05 10:19:12 +05:30
RameshT e827ec7b45 Test Husky pre-commit hook. 2024-08-05 10:11:20 +05:30
RameshT 75ff32ac2d Test Husky pre-commit hook. 2024-08-02 17:54:05 +05:30
RameshT becb0bf5ca Test Husky pre-commit hook. 2024-08-02 17:53:03 +05:30
RameshT 303350ea0a Test Husky pre-commit hook. 2024-08-02 17:51:50 +05:30
9 changed files with 300 additions and 113 deletions

1
.husky/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_

100
.husky/pre-commit Executable file
View File

@ -0,0 +1,100 @@
#!/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."

View File

@ -1,20 +1,25 @@
<?php <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Form extends CI_Controller { namespace application\controllers;
public function __construct() { defined('BASEPATH') or exit('No direct script access allowed');
// use application\models\Form_model;
class Form extends CI_Controller
{
public function __construct()
{
parent::__construct(); parent::__construct();
$this->load->model('Form_model'); $this->load->model('Form_model');
} }
public function submit()
public function submit() { {
if (!$this->session->userdata('logged_in')) { if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page // If not logged in, redirect to login page
redirect('users/login'); redirect('users/login');
} }$form_data = json_decode($this->input->raw_input_stream, true);
$form_data = json_decode($this->input->raw_input_stream, true); $this->load->model('Form_model');
if ($this->Form_model->save_form($form_data)) { if ($this->Form_model->save_form($form_data)) {
$response = array('status' => 'success', 'message' => 'Form submitted successfully.'); $response = array('status' => 'success', 'message' => 'Form submitted successfully.');
} else { } else {
@ -23,14 +28,11 @@ class Form extends CI_Controller {
echo json_encode($response); echo json_encode($response);
} }
public function view($form_id)
public function view($form_id) { {
$data['title'] = $this->Form_model->get_form_title($form_id); $data['title'] = $this->Form_model->get_form_title($form_id);
if ($data['title'] === null) { if ($data['title'] === null) {
show_404(); // Show 404 if form_id is invalid show_404(); // Show 404 if form_id is invalid
} }$this->load->view('templates/forms_ui', $data);
$this->load->view('templates/forms_ui',$data);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
defined('BASEPATH') or exit('No direct script access allowed'); defined('BASEPATH') or exit('No direct script access allowed');
class Forms extends CI_Controller class Forms extends CI_Controller
@ -9,6 +10,9 @@ class Forms extends CI_Controller
// If not logged in, redirect to login page // If not logged in, redirect to login page
redirect('users/login'); redirect('users/login');
} }
// Load the model that handles the form data // Load the model that handles the form data
$this->load->model('preview_model'); $this->load->model('preview_model');
@ -31,7 +35,6 @@ class Forms extends CI_Controller
$this->load->view('form_preview', $data); $this->load->view('form_preview', $data);
$this->load->view('templates/footer'); $this->load->view('templates/footer');
} }
public function response_preview($form_id) public function response_preview($form_id)
@ -70,7 +73,8 @@ class Forms extends CI_Controller
$this->load->view('response_submit', $data); $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 (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page // If not logged in, redirect to login page
redirect('users/login'); redirect('users/login');
@ -89,14 +93,13 @@ class Forms extends CI_Controller
foreach ($questions as &$question) { foreach ($questions as &$question) {
$question->options = $this->preview_model->get_options($question->id); $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['form'] = $form;
$data['questions'] = $questions; $data['questions'] = $questions;
$this->load->view('templates/header'); $this->load->view('templates/header');
$this->load->view('form_preview_back', $data); $this->load->view('form_preview_back', $data);
$this->load->view('templates/footer'); $this->load->view('templates/footer');
// $this->load->view('templates/footer');
} }
} }

View File

@ -1,8 +1,10 @@
<?php <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller { namespace application\controllers;
defined('BASEPATH') or exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function index() public function index()
{ {
$this->load->view('welcome_message'); $this->load->view('welcome_message');

View File

@ -1,26 +1,27 @@
$(document).ready(function() { $(document).ready(function () {
let index = 1; let index = 1
let activeSection = null; let activeSection = null
function addOption(type, container) { function addOption(type, container) {
let optionHtml; let optionHtml
if (type === 'multiple-choice' || type === 'checkboxes') { if (type === 'multiple-choice' || type === 'checkboxes') {
optionHtml = ` optionHtml = `
<div class="option"> <div class="option">
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled> <input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
<input type="text" class="form-control option-label"> <input type="text" class="form-control option-label">
<span class="delete-option-icon">&times;</span> <span class="delete-option-icon">&times;</span>
</div> </div>
`; `
} else if (type === 'dropdown') { } else if (type === 'dropdown') {
optionHtml = ` optionHtml = `
<div class="option"> <div class="option">
<input type="text" class="form-control option-label"> <input type="text" class="form-control option-label">
<span class="delete-option-icon">&times;</span> <span class="delete-option-icon">&times;</span>
</div> </div>
`; `
} }
container.append(optionHtml); container.append(optionHtml)
} }
function createFormSection() { function createFormSection() {
@ -44,50 +45,58 @@ $(document).ready(function() {
</div> </div>
<div class="options-container"></div> <div class="options-container"></div>
</div> </div>
`; `
$('#form-container').append(newSection); $('#form-container').append(newSection)
index++; index++
positionAddSectionButton(); positionAddSectionButton()
} }
function positionAddSectionButton() { function positionAddSectionButton() {
if (activeSection) { if (activeSection) {
let position = activeSection.position(); let position = activeSection.position()
let buttonWidth = $('#add-section-btn').outerWidth(); let buttonWidth = $('#add-section-btn').outerWidth()
let buttonHeight = $('#add-section-btn').outerHeight(); let buttonHeight = $('#add-section-btn').outerHeight()
$('#add-section-btn').css({ $('#add-section-btn').css({
position: 'absolute', position: 'absolute',
left: position.left - buttonWidth - 47 + 'px', left: position.left - buttonWidth - 47 + 'px',
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px' top:
}); position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px',
})
} }
} }
$('#add-section-btn').on('click', function() { $('#add-section-btn').on('click', function () {
createFormSection(); createFormSection()
$('.form-section').removeClass('active'); $('.form-section').removeClass('active')
activeSection = $('.form-section').last(); activeSection = $('.form-section').last()
activeSection.addClass('active'); activeSection.addClass('active')
positionAddSectionButton(); positionAddSectionButton()
}); })
$(document).on('change', '.custom-select', function() { $(document).on('change', '.custom-select', function () {
let type = $(this).val(); let type = $(this).val()
let container = $(this).closest('.form-section').find('.options-container'); let container = $(this).closest('.form-section').find('.options-container')
container.empty(); container.empty()
$(this).closest('.form-section').find('.add-option-btn').remove(); $(this).closest('.form-section').find('.add-option-btn').remove()
if (type === 'short-answer') { if (type === 'short-answer') {
container.append('<input type="text" class="form-control" disabled placeholder="Short answer text">'); container.append(
'<input type="text" class="form-control" disabled placeholder="Short answer text">'
)
} else if (type === 'paragraph') { } else if (type === 'paragraph') {
container.append('<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>'); container.append(
'<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>'
)
} else { } else {
addOption(type, container); addOption(type, container)
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>'); $(this)
.closest('.form-section')
.append(
'<button class="btn btn-secondary add-option-btn">Add Option</button>'
)
} }
}); })
})
});

View File

@ -6,21 +6,22 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install", "prepare": "husky install",
"lint": "eslint .", "lint": "eslint src --ext .js,.jsx --report-unused-disable-directives",
"lint:fix": "phpcbf && eslint . --fix" "lint-php": "phpcs --standard=PSR12 && phpcbf --standard=PSR12 && php-cs-fixer fix",
"format": "prettier --write"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.aissel.com/RameshT/google_forms.git" "url": "https://git.aissel.com/RameshT/google_forms.git"
}, },
"lint-staged": { "lint-staged": {
"*.php": [ "*.{js,jsx,ts,tsx,json,css,scss,md}": [
"phpcbf", "prettier --write"
"git add"
], ],
"*.js": [ "**/*.php": [
"eslint --fix", "phpcs --standard=PSR12",
"git add" "phpcbf --standard=PSR12",
"php-cs-fixer fix"
] ]
}, },
"keywords": [], "keywords": [],
@ -28,10 +29,14 @@
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.8.0", "@eslint/js": "^9.8.0",
"eslint": "^9.8.0", "eslint": "^7.32.0",
"globals": "^15.8.0", "eslint-config-prettier": "^9.1.0",
"husky": "^8.0.0", "eslint-plugin-html": "^8.1.1",
"lint-staged": "^15.2.7" "eslint-plugin-prettier": "^5.2.1",
"globals": "^15.9.0",
"husky": "^6.0.0",
"lint-staged": "^15.2.7",
"prettier": "^3.3.3"
}, },
"dependencies": { "dependencies": {
"ansi-escapes": "^7.0.0", "ansi-escapes": "^7.0.0",

14
phpcs.xml Normal file
View File

@ -0,0 +1,14 @@
<?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>

51
settings.json Normal file
View File

@ -0,0 +1,51 @@
{
"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"
}
}