Browse Source

Add group assignment to jobs

master
Skylar Ittner 2 years ago
parent
commit
7e3246c6c0
9 changed files with 120 additions and 6 deletions
  1. 11
    1
      action.php
  2. BIN
      database.mwb
  3. 1
    1
      database_upgrade/1.0.1_1.1.sql
  4. 4
    1
      pages.php
  5. 57
    0
      pages/editjob.php
  6. 1
    1
      pages/editjobhistory.php
  7. 1
    1
      pages/jobs.php
  8. 44
    0
      static/js/editjob.js
  9. 1
    1
      static/js/editjobs.js

+ 11
- 1
action.php View File

@@ -252,7 +252,7 @@ switch ($VARS['action']) {
foreach ($groups as $g) {
$gids[] = $g['id'];
}
$job = $database->has('jobs', ['[>]job_groups' => ['jobid']], ["AND" => ['groupid' => $gids, 'jobs.jobid' => $VARS['job']]]);
$job = $database->has('jobs', ['[>]job_groups' => ['jobid']], ["AND" => ["OR" => ['groupid' => $gids, 'groupid #-1' => -1], 'deleted' => 0]]);
} else {
$job = $database->has('jobs', 'jobid', ['jobid' => $VARS['job']]);
}
@@ -273,15 +273,25 @@ switch ($VARS['action']) {
$name = htmlentities($VARS['jobname']);
$code = $VARS['jobcode'];
$color = $VARS['color'];
$groups = $VARS['groups'];

if (is_empty($VARS['jobid'])) {
if ($database->has('jobs', ['jobname' => $name])) {
returnToSender("job_name_used");
}
$database->insert('jobs', ["jobname" => $name, "jobcode" => $code, "color" => $color]);
$jobid = $database->id();
$database->delete('job_groups', ['jobid' => $jobid]);
foreach ($groups as $g) {
$database->insert('job_groups', ['jobid' => $jobid, 'groupid' => $g]);
}
returnToSender("job_added");
} else if ($database->has('jobs', ['jobid' => $VARS['jobid']])) {
$database->update('jobs', ["jobname" => $name, "jobcode" => $code, "color" => $color], ["jobid" => $VARS['jobid']]);
$database->delete('job_groups', ['jobid' => $VARS['jobid']]);
foreach ($groups as $g) {
$database->insert('job_groups', ['jobid' => $VARS['jobid'], 'groupid' => $g]);
}
returnToSender("job_saved");
} else {
returnToSender("invalid_jobid");

BIN
database.mwb View File


+ 1
- 1
database_upgrade/1.0.1_1.1.sql View File

@@ -16,7 +16,7 @@ DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `job_groups` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`groupid` VARCHAR(45) NOT NULL,
`groupid` INT(11) NOT NULL,
`jobid` INT(11) NOT NULL,
PRIMARY KEY (`id`, `groupid`, `jobid`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),

+ 4
- 1
pages.php View File

@@ -59,7 +59,10 @@ define("PAGES", [
],
"editjob" => [
"title" => "edit job",
"navbar" => false
"navbar" => false,
"scripts" => [
"static/js/editjob.js"
]
],
"editjobhistory" => [
"title" => "edit job",

+ 57
- 0
pages/editjob.php View File

@@ -83,6 +83,63 @@ if (isset($VARS['job']) && $database->has('jobs', ['jobid' => $VARS['job']])) {
</select>
</div>
</div>
<div class="col-xs-12 col-md-6">
<label for="groups-box"><i class="fa fa-object-group"></i> <?php lang("visible to groups"); ?></label><br />
<div class="row">
<div class="col-xs-8 col-sm-10 col-md-9 col-lg-10">
<select id="groups-box" class="form-control">
<option value=""><?php lang("choose a group"); ?></option>
<option value="-1"><?php lang("all groups"); ?></option>
<?php
$all_groups = [];
$client = new GuzzleHttp\Client();

$response = $client
->request('POST', PORTAL_API, [
'form_params' => [
'key' => PORTAL_KEY,
'action' => "getgroups"
]
]);

if ($response->getStatusCode() > 299) {
echo "Error: " . $response->getBody();
}

$resp = json_decode($response->getBody(), TRUE);
if ($resp['status'] == "OK") {
foreach ($resp['groups'] as $g) {
echo '<option value="' . $g['id'] . '">' . $g['name'] . '</option>';
$all_groups[$g['id']] = $g['name'];
}
}
?>
</select>
</div>
<div class="col-xs-4 col-sm-2 col-md-3 col-lg-2">
<button class="btn btn-default" type="button" id="addgroupbtn"><i class="fa fa-plus"></i> <?php lang("add") ?></button>
</div>
</div>
<div class="panel" id="groupslist-panel">
<div class="list-group" id="groupslist">
<?php
$groups = $database->select('job_groups', ['groupid (id)'], ['jobid' => $data['jobid']]);
foreach ($groups as $g) {
if ($g['id'] == -1) {
$g['name'] = lang("all groups", false);
} else {
$g['name'] = $all_groups[$g['id']];
}
?>
<div class="list-group-item" data-groupid="<?php echo $g['id']; ?>">
<?php echo $g['name']; ?> <div class="btn btn-danger btn-sm pull-right rm"><i class="fa fa-trash-o"></i></div><input type="hidden" name="groups[]" value="<?php echo $g['id']; ?>" />
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>


+ 1
- 1
pages/editjobhistory.php View File

@@ -56,7 +56,7 @@ if (isset($VARS['job']) && $database->has('job_tracking', ['id' => $VARS['job']]
foreach ($groups as $g) {
$gids[] = $g['id'];
}
$jobs = $database->select('jobs', ['[>]job_groups' => ['jobid']], ['jobs.jobid', 'jobname'], ["AND" => ['groupid' => $gids, 'deleted' => 0]]);
$jobs = $database->select('jobs', ['[>]job_groups' => ['jobid']], ['jobs.jobid', 'jobname'], ["AND" => ["OR" => ['groupid' => $gids, 'groupid #-1' => -1], 'deleted' => 0]]);
} else {
$jobs = $database->select('jobs', ['jobid', 'jobname'], ['deleted' => 0]);
}

+ 1
- 1
pages/jobs.php View File

@@ -28,7 +28,7 @@ redirectifnotloggedin();
foreach ($groups as $g) {
$gids[] = $g['id'];
}
$jobs = $database->select('jobs', ['[>]job_groups' => ['jobid']], ['jobs.jobid', 'jobname', 'jobcode', 'color'], ["AND" => ['groupid' => $gids, 'deleted' => 0]]);
$jobs = $database->select('jobs', ['[>]job_groups' => ['jobid']], ['jobs.jobid', 'jobname', 'jobcode', 'color'], ["AND" => ["OR" => ['groupid' => $gids, 'groupid #-1' => -1], 'deleted' => 0]]);
} else {
$jobs = $database->select('jobs', ['jobid', 'jobname', 'jobcode', 'color'], ['deleted' => 0]);
}

+ 44
- 0
static/js/editjob.js View File

@@ -0,0 +1,44 @@
/*
* 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 http://mozilla.org/MPL/2.0/.
*/


/* 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 http://mozilla.org/MPL/2.0/. */

function addGroup(id, name) {
id = id.trim();
if (id == "") {
return false;
}
if ($("#groupslist div[data-groupid=" + id + "]").length) {
$("#groupslist .list-group-item[data-groupid=" + id + "]").animate({
backgroundColor: "#ff0000",
}, 500, "linear", function () {
$("#groupslist .list-group-item[data-groupid=" + id + "]").animate({
backgroundColor: "#ffffff",
}, 500);
});
return false;
}
$('#groupslist').append("<div class=\"list-group-item\" data-groupid=\"" + id + "\">" + name + "<div class=\"btn btn-danger btn-sm pull-right rm\"><i class=\"fa fa-trash-o\"></i></div><input type=\"hidden\" name=\"groups[]\" value=\"" + id + "\" /></div>");
}

function removeGroup(gid) {
$("#groupslist div[data-groupid=" + gid + "]").remove();
}

$("#addgroupbtn").click(function () {
addGroup($("#groups-box").val(), $("#groups-box option:selected").text());
});

$('#groupslist').on("click", ".rm", function () {
removeGroup($(this).parent().data("groupid"));
});

$('#groups-box').change(function () {
addGroup($("#groups-box").val(), $("#groups-box option:selected").text());
});

+ 1
- 1
static/js/editjobs.js View File

@@ -29,6 +29,6 @@ var jobtable = $('#jobtable').DataTable({
}
],
order: [
[2, 'desc']
[2, 'asc']
]
});

Loading…
Cancel
Save