Skip to content

Commit

Permalink
feat: edit forms via administration
Browse files Browse the repository at this point in the history
  • Loading branch information
modelrailroader committed Mar 28, 2024
1 parent 60279d1 commit 016c455
Show file tree
Hide file tree
Showing 39 changed files with 1,798 additions and 121 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 35 additions & 35 deletions kubernetes-deploy/01-phpmyfaq-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,40 @@ spec:
app: phpmyfaq
spec:
containers:
- image: ${registry}:phpmyfaq:3.2
imagePullPolicy: Always
name: phpmyfaq
env:
- name: PMF_DB_HOST # use any mysql kubernetes deployment. Ej. MYSQL BITNAMY HELM CHART
value: ${host}
- name: PMF_DB_NAME
value: "db_phpmyfaq"
- name: PMF_DB_USER
value: "phpmyfaq"
- name: PMF_DB_PASS
value: ${pass}
- name: PHP_LOG_ERRORS
value: "On"
ports:
- containerPort: 80
protocol: TCP
name: http
- containerPort: 443
protocol: TCP
name: https
volumeMounts:
- mountPath: /etc/apache2/ssl/cert-key.pem
name: certs
subPath: tls.key
- mountPath: /etc/apache2/ssl/cert.pem
name: certs
subPath: tls.crt
- mountPath: /var/www/html
name: data
subPath: html
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
- image: ${registry}:phpmyfaq:3.2
imagePullPolicy: Always
name: phpmyfaq
env:
- name: PMF_DB_HOST # use any mysql kubernetes deployment. Ej. MYSQL BITNAMY HELM CHART
value: ${host}
- name: PMF_DB_NAME
value: 'db_phpmyfaq'
- name: PMF_DB_USER
value: 'phpmyfaq'
- name: PMF_DB_PASS
value: ${pass}
- name: PHP_LOG_ERRORS
value: 'On'
ports:
- containerPort: 80
protocol: TCP
name: http
- containerPort: 443
protocol: TCP
name: https
volumeMounts:
- mountPath: /etc/apache2/ssl/cert-key.pem
name: certs
subPath: tls.key
- mountPath: /etc/apache2/ssl/cert.pem
name: certs
subPath: tls.crt
- mountPath: /var/www/html
name: data
subPath: html
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumes:
- name: certs
secret:
Expand All @@ -69,4 +69,4 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 0
terminationGracePeriodSeconds: 0
17 changes: 9 additions & 8 deletions kubernetes-deploy/02-phpmyfaq-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ metadata:
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 80
protocol: TCP
- name: https
port: 443
protocol: TCP
- name: http
port: 80
protocol: TCP
- name: https
port: 443
protocol: TCP
selector:
app: phpmyfaq
sessionAffinity: None
type: ClusterIP
---
---

27 changes: 14 additions & 13 deletions kubernetes-deploy/03-phpmyfaq-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ metadata:
annotations:
cert-manager.io/cluster-issuer: selfsigned-issuer # provided by cert-manager install/config
cert-manager.io/common-name: faq.sample.domain
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/ssl-redirect: 'true'
nginx.ingress.kubernetes.io/backend-protocol: 'HTTPS'
spec:
ingressClassName: nginx
tls:
- hosts:
- faq.sample.domain
secretName: faq-tls-<ENV_ROLE>
rules:
- host: faq.sample.domain
http:
paths:
- backend:
service:
name: phpmyfaq
port:
number: 443
path: /
pathType: Prefix
---
- host: faq.sample.domain
http:
paths:
- backend:
service:
name: phpmyfaq
port:
number: 443
path: /
pathType: Prefix
---

183 changes: 183 additions & 0 deletions phpmyfaq/admin/assets/src/api/forms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/**
* API fetch requests for form editing
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author Jan Harms <modelrailroader@gmx-topmail.de>
* @copyright 2024 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2014-03-21
*/

import { pushNotification } from '../utils';

export const fetchActivateInput = async (csrf, formId, inputId, checked) => {
try {
const response = await fetch('api/forms/activate', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
formid: formId,
inputid: inputId,
checked: checked,
}),
});

if (response.ok) {
const result = await response.json();
if (result.success) {
pushNotification(result.success);
} else {
console.error(result.error);
}
} else {
throw new Error('Network response was not ok: ', response.text());
}
} catch (error) {
console.error('Error activating/deactivating input:', error);
throw error;
}
};

export const fetchSetInputAsRequired = async (csrf, formId, inputId, checked) => {
try {
const response = await fetch('api/forms/required', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
formid: formId,
inputid: inputId,
checked: checked,
}),
});

if (response.ok) {
const result = await response.json();
if (result.success) {
pushNotification(result.success);
} else {
console.error(result.error);
}
} else {
throw new Error('Network response was not ok: ', response.text());
}
} catch (error) {
console.error('Error setting input as required:', error);
throw error;
}
}

export const fetchEditTranslation = async (csrf, formId, inputId, label, lang) => {
try {
const response = await fetch('api/forms/translation-edit', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
formId: formId,
inputId: inputId,
lang: lang,
label: label,
}),
});

if (response.ok) {
const result = await response.json();
if (result.success) {
pushNotification(result.success);
} else {
console.error(result.error);
}
} else {
throw new Error('Network response was not ok: ', response.text());
}
} catch (error) {
console.error('Error editing translation:', error);
throw error;
}
}

export const fetchDeleteTranslation = async (csrf, formId, inputId, lang) => {
try {
const response = await fetch('api/forms/translation-delete', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
formId: formId,
inputId: inputId,
lang: lang
}),
});

if (response.ok) {
const result = await response.json();
if (result.success) {
pushNotification(result.success);
document.getElementById('item_' + element.getAttribute('data-pmf-lang')).remove();
} else {
console.error(result.error);
}
} else {
throw new Error('Network response was not ok: ', response.text());
}
} catch {
console.error('Error deleting translation:', error);
throw error;
}
}

export const fetchAddTranslation = async (csrf, formId, inputId, lang, translation) => {
try {
const response = await fetch('api/forms/translation-add', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrf: csrf,
formId: formId,
inputId: inputId,
lang: lang,
translation: translation,
}),
});

if (response.ok) {
const result = await response.json();
if (result.success) {
pushNotification(result.success);
setTimeout(function () {
window.location.reload();
}, 3000);
} else {
console.error(result.error);
}
} else {
throw new Error('Network response was not ok: ', response.text());
}
} catch {
console.error('Error adding translation:', error);
throw error;
}
}

0 comments on commit 016c455

Please sign in to comment.