Skip to content

Commit b777175

Browse files
committed
NEW: custom-fields
1 parent 559261d commit b777175

File tree

9 files changed

+447
-15
lines changed

9 files changed

+447
-15
lines changed

header.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,19 @@
501501
<?= lang('General settings') ?>
502502
</a>
503503
<a href="<?= ROOTPATH ?>/admin/roles" class="with-icon <?= $pageactive('admin/roles') ?>">
504-
<i class="ph ph-gear" aria-hidden="true"></i>
504+
<i class="ph ph-shield-check" aria-hidden="true"></i>
505505
<?= lang('Roles &amp; Rights', 'Rollen &amp; Rechte') ?>
506506
</a>
507+
<a href="<?= ROOTPATH ?>/admin/fields" class="with-icon <?= $pageactive('admin/fields') ?>">
508+
<i class="ph ph-textbox" aria-hidden="true"></i>
509+
<?= lang('Custom fields') ?>
510+
</a>
507511
<a href="<?= ROOTPATH ?>/admin/categories" class="with-icon <?= $pageactive('admin/categories') ?>">
508-
<i class="ph ph-gear" aria-hidden="true"></i>
512+
<i class="ph ph-bookmarks" aria-hidden="true"></i>
509513
<?= lang('Activities', 'Aktivitäten') ?>
510514
</a>
511515
<a href="<?= ROOTPATH ?>/admin/features" class="with-icon <?= $pageactive('admin/features') ?>">
512-
<i class="ph ph-gear" aria-hidden="true"></i>
516+
<i class="ph ph-toolbox" aria-hidden="true"></i>
513517
<?= lang('Features', 'Funktionen') ?>
514518
</a>
515519
</nav>

pages/activity-search.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,33 @@ function run() {
439439
label: lang('Updated by (Abbreviation)', 'Aktualisiert von (Kürzel)'),
440440
type: 'string'
441441
},
442+
<?php
443+
foreach ($osiris->adminFields->find() as $field) {
444+
$f = [
445+
'id'=> $field['id'],
446+
'label'=> lang($field['name'], $field['name_de']??null),
447+
'type'=> $field['format']
448+
];
449+
450+
if ($field['format']=='boolean'){
451+
$f['values'] = [
452+
'true'=> 'yes',
453+
'false'=> 'no'
454+
];
455+
$f['input'] = 'radio';
456+
}
457+
458+
if ($field['format']=='list'){
459+
$f['type'] = 'string';
460+
$f['values'] = $field['values'];
461+
$f['input'] = 'select';
462+
}
463+
464+
echo json_encode($f);
465+
echo ',';
466+
}
467+
468+
?>
442469
// {
443470
// id: 'updated',
444471
// label: lang('Updated', ''),

pages/admin/categories.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

33
/**
4-
* Page to browse all user groups
4+
* Page to browse all categories
55
*
66
* This file is part of the OSIRIS package.
77
* Copyright (c) 2024, Julia Koblitz
88
*
9-
* @link /groups
9+
* @link /admin/categories
1010
*
1111
* @package OSIRIS
1212
* @since 1.3.0

pages/admin/category-type.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$name = str_replace('*', '', $name);
2222
}
2323
$f = $Modules->all_modules[$name] ?? array();
24-
$EXAMPLE = array_merge($f['fields'], $EXAMPLE);
24+
$EXAMPLE = array_merge($f['fields'] ?? [], $EXAMPLE);
2525
}
2626
include_once BASEPATH . "/php/Document.php";
2727
$Document = new Document(false, 'print');
@@ -182,9 +182,22 @@
182182
<select class="module-input form-control">
183183
<option value="" disabled selected><?= lang('Add module ...', 'Füge Module hinzu ...') ?></option>
184184
<?php
185+
// read custom modules first
186+
$custom_modules = $osiris->adminFields->distinct('id');
187+
if (!empty($custom_modules)){
188+
foreach ($custom_modules as $m) {
189+
if (in_array($m, $module_lst)) continue;
190+
?>
191+
<option><?= $m ?></option>
192+
<?php } ?>
193+
<option disabled>---</option>
194+
<?php
195+
}
185196
include_once BASEPATH . "/php/Modules.php";
186197
$Modules = new Modules();
187-
foreach ($Modules->all_modules as $m => $_) {
198+
$all_modules = array_keys($Modules->all_modules);
199+
sort($all_modules);
200+
foreach ($all_modules as $m) {
188201
if (in_array($m, $module_lst)) continue;
189202
?>
190203
<option><?= $m ?></option>

pages/admin/field.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
$formaction = ROOTPATH;
3+
// if (!empty($form) && isset($form['_id'])) {
4+
// $formaction .= "/crud/fields/update/" . $form['_id'];
5+
// $btntext = '<i class="ph ph-check"></i> ' . lang("Update", "Aktualisieren");
6+
// $url = ROOTPATH . "/admin/fields/" . $form['id'];
7+
// $title = $name;
8+
// } else {
9+
$formaction .= "/crud/fields/create";
10+
$btntext = '<i class="ph ph-check"></i> ' . lang("Save", "Speichern");
11+
$url = ROOTPATH . "/admin/fields";
12+
$title = lang('New field', 'Neues Feld');
13+
// }
14+
15+
?>
16+
<style>
17+
tr.ui-sortable-helper {
18+
background-color: white;
19+
border: 1px solid var(--border-color);
20+
}
21+
</style>
22+
23+
<form action="<?= $formaction ?>" method="post" id="group-form">
24+
25+
<div class="box">
26+
<h4 class="header">
27+
<?= $title ?>
28+
</h4>
29+
30+
<div class="content">
31+
32+
<div class="form-group">
33+
<label for="id">ID</label>
34+
<input type="text" class="form-control" name="values[id]" id="id">
35+
<small class="form-text">
36+
<?= lang('Important! The ID will be used in the module list and in templates. Choose sth precise, unique and without spaces.', 'Wichtig! Die ID wird in der Modulliste gezeigt, wähle also etwas genaues, einzigartiges und nutze kein Leerzeichen!') ?>
37+
</small>
38+
</div>
39+
40+
41+
<div class="row row-eq-spacing">
42+
<div class="col-sm-6">
43+
<label for="name" class="required ">Name (en)</label>
44+
<input type="text" class="form-control" name="values[name]" required>
45+
</div>
46+
<div class="col-sm-6">
47+
<label for="name_de" class="">Name (de)</label>
48+
<input type="text" class="form-control" name="values[name_de]">
49+
</div>
50+
</div>
51+
52+
<div class="row row-eq-spacing">
53+
<div class="col-sm-6">
54+
<label for="format">Format</label>
55+
<select class="form-control" name="values[format]" id="format" onchange="updateFields(this.value)">
56+
<option value="string">Text</option>
57+
<option value="text">Long text</option>
58+
<option value="int">Integer</option>
59+
<option value="float">Float</option>
60+
<option value="list">List</option>
61+
<option value="date">Date</option>
62+
<option value="bool">Boolean</option>
63+
<!-- <option value="user">User</option> -->
64+
</select>
65+
</div>
66+
<div class="col-sm-6">
67+
68+
<label for="default">Default</label>
69+
<input type="text" class="form-control" name="values[default]" id="default">
70+
71+
</div>
72+
</div>
73+
74+
75+
76+
<fieldset id="values-field" style="display: none;">
77+
<legend><?= lang('Possible values', 'Mögliche Werte') ?></legend>
78+
<table class="table simple small">
79+
<tbody id="possible-values">
80+
<tr>
81+
<td class="w-50">
82+
<i class="ph ph-dots-six-vertical text-muted handle"></i>
83+
</td>
84+
<td>
85+
<input type="text" class="form-control" name="values[values][]">
86+
</td>
87+
<td>
88+
<a onclick="$(this).closest('tr').remove()"><i class="ph ph-trash"></i></a>
89+
</td>
90+
</tr>
91+
</tbody>
92+
</table>
93+
<button class="btn" type="button" onclick="addValuesRow()"><i class="ph ph-plus-circle"></i></button>
94+
</fieldset>
95+
96+
97+
<button type="submit" class="btn success" id="submitBtn"><?= $btntext ?></button>
98+
99+
</div>
100+
101+
102+
</form>
103+
104+
105+
<script src="<?= ROOTPATH ?>/js/jquery-ui.min.js"></script>
106+
<script>
107+
function addValuesRow() {
108+
$('#possible-values').append(`
109+
<tr>
110+
<td class="w-50">
111+
<i class="ph ph-dots-six-vertical text-muted handle"></i>
112+
</td>
113+
<td>
114+
<input type="text" class="form-control" name="values[values][]">
115+
</td>
116+
<td>
117+
<a onclick="$(this).closest('tr').remove()"><i class="ph ph-trash"></i></a>
118+
</td>
119+
</tr>
120+
`);
121+
}
122+
123+
function updateFields(name) {
124+
$('#values-field').hide()
125+
switch (name) {
126+
case 'string':
127+
break;
128+
case 'text':
129+
break;
130+
case 'int':
131+
break;
132+
case 'float':
133+
break;
134+
case 'list':
135+
$('#values-field').show()
136+
break;
137+
case 'date':
138+
break;
139+
case 'bool':
140+
break;
141+
default:
142+
break;
143+
}
144+
}
145+
146+
$(document).ready(function() {
147+
$('#possible-values').sortable({
148+
handle: ".handle",
149+
// change: function( event, ui ) {}
150+
});
151+
})
152+
</script>

pages/admin/fields.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Page to see and edit custom fields
5+
*
6+
* This file is part of the OSIRIS package.
7+
* Copyright (c) 2024, Julia Koblitz
8+
*
9+
* @link /admin/fields
10+
*
11+
* @package OSIRIS
12+
* @since 1.3.1
13+
*
14+
* @copyright Copyright (c) 2024, Julia Koblitz
15+
* @author Julia Koblitz <julia.koblitz@dsmz.de>
16+
* @license MIT
17+
*/
18+
19+
?>
20+
21+
<h1>
22+
<i class="ph ph-textbox"></i>
23+
Custom fields
24+
</h1>
25+
26+
<div class="btn-toolbar">
27+
<a class="btn" href="<?= ROOTPATH ?>/admin/fields/new">
28+
<i class="ph ph-plus-circle"></i>
29+
<?= lang('Add field', 'Feld hinzufügen') ?>
30+
</a>
31+
</div>
32+
<table class="table">
33+
<thead>
34+
<tr>
35+
<th>ID</th>
36+
<th>Format</th>
37+
<th>Name</th>
38+
<th></th>
39+
</tr>
40+
</thead>
41+
<?php foreach ($osiris->adminFields->find() as $field) { ?>
42+
<tr>
43+
<td>
44+
<?=$field['id']?>
45+
</td>
46+
<td>
47+
<?=$field['format']?>
48+
</td>
49+
<td>
50+
<?=lang($field['name'], $field['name_de'])?>
51+
</td>
52+
<td>
53+
<form action="<?=ROOTPATH?>/crud/fields/delete/<?=$field['_id']?>" method="post">
54+
<button type="submit" class="btn link"><i class="ph ph-trash text-danger"></i></button>
55+
</form>
56+
</td>
57+
</tr>
58+
<?php } ?>
59+
</table>

0 commit comments

Comments
 (0)