Started creating workflow

This commit is contained in:
Frank Schubert
2021-08-24 21:40:30 +02:00
parent 7ad852c4ef
commit 2e9d5d5767
22 changed files with 717 additions and 1 deletions

View File

@@ -353,6 +353,7 @@
<div class="card-body">
<h4>Produkte</h4>
<?php if(is_array($order->products) && count($order->products)): ?>
<?php foreach($order->products as $product): ?>
<div class="row product-container">
<div class="col-md-1 product-<?=$product->id?>">
@@ -438,6 +439,7 @@
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="row product-container">

View File

@@ -0,0 +1,164 @@
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
<li class="breadcrumb-item active">Tiefbau</li>
</ol>
</div>
<h4 class="page-title">Tiefbau</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<div class="float-left">
<h4 class="header-title">Auftragsliste</h4>
</div>
<table class="table table-striped table-hover">
<tr>
<th>Netzgebiet</th>
<th>POP</th>
<th>Typ</th>
<th>Objektcode</th>
<th>OAN ID</th>
<th>Adresse</th>
<th>Einheiten</th>
<th>Status</th>
<th></th>
</tr>
<?php foreach($buildings as $building): ?>
<tr class="building-list-tr" id="building-<?=$building->id?>">
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->network->name?></td>
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->pop->name?></td>
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->type->name?></td>
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->code?></td>
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->oan_id?></td>
<td onclick="toggleBuilding(<?=$building->id?>)">
<?=$building->street?><br />
<?=$building->zip?> <?=$building->city?>
</td>
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->units?></td>
<td onclick="toggleBuilding(<?=$building->id?>)" class="text-monospace"><?=__($building->status->name."-b")?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<!--<a href="<?=self::getUrl("Building", "edit", ["id" => $building->id])?>"><i class="far fa-edit" title="Objekt Bearbeiten"></i></a>
<a href="<?=self::getUrl("Building", "delete", ["id" => $building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"><i class="fas fa-trash"></i></a> -->
</td>
</tr>
<tr id="building-detail-<?=$building->id?>" style="display:none; background-color:#fff">
<td colspan="8">
<div class="card">
<div class="card-body">
<h4 class="card-title">Tätigkeiten im Objekt <strong><?=$building->code?></strong></h4>
<p>
<?=$building->street?><br />
<?=$building->zip?> <?=$building->city?>
</p>
<div class="card">
<div class="card-body">
<form method="post" action="<?=self::getUrl("Pipework","save")?>" >
<input type="hidden" name="building_id" value="<?=$building->id?>" />
<?php foreach($building->workflowitems as $item): ?>
<?php include(realpath(dirname(__FILE__)."/../")."/Workflow/form.php"); ?>
<?php endforeach; ?>
<button type="submit" class="btn btn-primary">Speichern</button>
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr style="display:none;">
<td colspan="3"></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function toggleBuilding(id) {
$('#building-detail-' + id).toggle();
if($('#building-detail-' + id).is(":hidden")) {
$('#building-' + id).removeClass("table-info");
$('#building-' + id).removeClass("text-info");
} else {
$('#building-' + id).addClass("text-info");
$('#building-' + id).addClass("table-info");
}
}
function toggleTerminationControl(id, type) {
$("#term-" + type + "-" + id + "-text").toggle();
$("#term-" + type + "-" + id + "-input").toggle();
$("#term-" + type + "-" + id + "-edit").toggle();
}
function saveTerminationControl(id, type) {
if(!Number.isInteger(id) || id < 1) {
return false;
}
var value = $("#term-" + type + "-" + id + "-input input[type=text]").val();
$.post("<?=self::getUrl("Termination","Api")?>",
{
'do': "setValue",
id: id,
type: type,
value: value
},
function(success) {
if(success.status == "OK") {
$("#term-" + type + "-" + id + "-text").text(value);
} else {
console.log("error saving (" + type + ", '" + value + "')");
}
toggleTerminationControl(id, type);
},
'json');
}
var building;
var hash = window.location.hash.substr(1);
var match = hash.match(/building=(\d+)/);
if(match && match[1]) {
building = match[1]
toggleBuilding(building);
//$('body').scrollTop($('#building-' + building).offset() - 50);
}
</script>
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>

View File

@@ -0,0 +1,41 @@
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="wfitem_<?=$item->name?>">
<?=$item->label?>
<?=($item->required == 1) ? "*" : ""?>
</label>
<div class="col-lg-10">
<?php
switch($item->type) {
case "string":
include(realpath(dirname(__FILE__)."/items/")."/string.php");
break;
case "int":
include(realpath(dirname(__FILE__)."/items/")."/int.php");
break;
case "bool":
include(realpath(dirname(__FILE__)."/items/")."/bool.php");
break;
case "enum":
include(realpath(dirname(__FILE__)."/items/")."/enum.php");
break;
case "text":
include(realpath(dirname(__FILE__)."/items/")."/text.php");
break;
case "file":
include(realpath(dirname(__FILE__)."/items/")."/file.php");
break;
case "gps":
include(realpath(dirname(__FILE__)."/items/")."/gps.php");
break;
case "color":
include(realpath(dirname(__FILE__)."/items/")."/color.php");
break;
case "delimiter":
include(realpath(dirname(__FILE__)."/items/")."/delimiter.php");
break;
}
?>
</div>
</div>

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>">

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>">

View File

@@ -0,0 +1 @@
<hr />

View File

@@ -0,0 +1,21 @@
<?php
$options = [];
$options = explode(";", $item->typedata);
?>
<select class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>">
<option></option>
<?php foreach($options as $opt): ?>
<?php
$key = $opt;
$label = $opt;
if(strpos($opt, "=") !== false) {
$opt_parts = explode('=', $opt);
$key = $opt_parts[0];
$label = $opt_parts[1];
}
?>
<option value="<?=$key?>"><?=$label?></option>
<?php endforeach; ?>
</select>

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>">

View File

@@ -0,0 +1,26 @@
<?php
$lat = "";
$long = "";
if($item->value_string) {
$gps_parts = explode(";", $item->value_string);
$lat = $gps_parts[0];
$long = $gps_parts[1];
}
?>
<div class="form-group row">
<label class="col-lg-1 col-form-label" for="wfitem_<?=$item->name?>_lat_<?=$building->id?>">GPS Breite:</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="wfitem_<?=$item->name?>_lat" id="wfitem_<?=$item->name?>_lat_<?=$building->id?>" value="<?=$lat?>" placeholder="<?=str_replace(",", ".", TT_PLACEHOLDER_GPS_LAT)?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-1 col-form-label" for="wfitem_<?=$item->name?>_long_<?=$building->id?>">GPS Länge:</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="wfitem_<?=$item->name?>_lat" id="wfitem_<?=$item->name?>_long_<?=$building->id?>" value="<?=$long?>" placeholder="<?=str_replace(",", ".", TT_PLACEHOLDER_GPS_LONG)?>">
</div>
</div>
<?php if($lat && $long): ?>
<a href="https://www.google.com/maps/search/?api=1&query=<?=$lat?>,<?=$long?>" target="_blank"><i class="fas fa-external-link-alt"></i> Auf Google Maps öffnen</a>
<?php endif; ?>

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>">

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>" placeholder="<?=$item->placeholder?>">

View File

@@ -0,0 +1 @@
<input type="text" class="form-control" name="wfitem_<?=$item->name?>" id="wfitem_<?=$item->name?>" value="<?=$item->value->value_string?>">

View File

@@ -37,6 +37,8 @@
</a>
<ul class="submenu">
<li><a href="<?=self::getUrl("Building")?>">Objekte & Anschlüsse</a></li>
<li><a href="<?=self::getUrl("Pipework")?>">Tiefbau</a></li>
<li><a href="<?=self::getUrl("Lineworker")?>">Leitungsbau</a></li>
</ul>
</li>
<?php endif; ?>

View File

@@ -9,6 +9,7 @@ class Building extends mfBaseModel {
private $status;
private $pipeworker;
private $terminations;
private $workflowitems;
public function getAddress($singelLine = false) {
if(!$this->id) {
@@ -122,6 +123,14 @@ class Building extends mfBaseModel {
return $this->terminations;
}
if($name == "workflowitems") {
foreach(WorkflowitemModel::search(["object_type" => "building", "active" => 1]) as $item) {
$item->setObjectId($this->id);
$this->workflowitems[] = $item;
}
return $this->workflowitems;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);

View File

@@ -145,7 +145,7 @@ class OrderModel {
$res = $db->select("Order", "*", "$where ORDER BY id");
}
if($db->num_rows($res)) {
while($data = $db->fetch_object()) {
while($data = $db->fetch_object($res)) {
$items[] = new Order($data);
}
}

View File

@@ -0,0 +1,39 @@
<?php
class PipeworkController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->is(["Admin", "netowner", "pipeplanner", "pipeworker"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction() {
$this->layout()->setTemplate("Pipework/Index");
if($this->me->is("Admin")) {
$this->layout()->set("buildings", BuildingModel::search(["workflow_finished" => 0]));
} else {
$buildings = [];
foreach($this->me->my_networks as $network) {
foreach(BuildingModel::search(["network_id" => $network->id, "workflow_finished" => 0]) as $b) {
if(!array_key_exists($b->id, $buildings)) {
$buildings[$b->id] = $b;
}
}
}
//var_dump($buildings);exit;
$this->layout()->set("buildings", $buildings);
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
class Workflowitem extends mfBaseModel {
private $value;
private $object_id;
public function setObjectId($object_id) {
if(!is_numeric($object_id)) {
return false;
}
$this->object_id = $object_id;
return true;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "value") {
if(!$this->object_id) {
$this->log->warn(__CLASS__."::getProperty('value'): Object ID not set");
return null;
}
$value = WorkflowvalueModel::getFirst(['item_id' => $this->id, "object_id" => $this->object_id]);
if(!$value) {
$vdata['item_id'] = $this->id;
$vdata['object_id'] = $this->object_id;
$value = WorkflowvalueModel::create($vdata);
}
$this->value = $value;
return $this->value;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,149 @@
<?php
class WorkflowitemModel {
public $owner_id;
public $object_type;
public $active;
public $required;
public $name;
public $label;
public $description;
public $type;
public $typedata;
public $placeholder;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new Workflowitem();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Workflowitem", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Workflowitem($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Workflowitem", "*", "1=1 ORDER BY name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Workflowitem($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Workflowitem", "*", "$where ORDER BY name");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Workflowitem($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
//var_dump($where);exit;
$res = $db->select("Workflowitem", "*", "$where ORDER BY num");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Workflowitem($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
//var_dump($filter);exit;
if(array_key_exists("active", $filter)) {
$active = $filter['active'];
if($active == 1) {
$where .= " AND active = 1";
}
if($active == 0) {
$where .= " AND active = 0";
}
}
if(array_key_exists("create_by", $filter)) {
$create_by = $filter['create_by'];
if(is_numeric($create_by)) {
$where .= " AND create_by=$create_by";
}
}
if(array_key_exists("name", $filter)) {
$name = FronkDB::singleton()->escape($filter['name']);
if($name) {
$where .= " AND name='$name'";
}
}
if(array_key_exists("object_type", $filter)) {
$otype = $filter['object_type'];
if(strtolower($otype) == "building") {
$where .= " AND object_type='Building'";
}
if(strtolower($otype) == "termination") {
$where .= " AND object_type='Termination'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,27 @@
<?php
class Workflowvalue extends mfBaseModel {
private $item;
public function getProperty($name) {
if($this->$name == null) {
if($name == "item") {
$this->item = new Workflowitem($this->item_id);
return $this->item;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,142 @@
<?php
class WorkflowvalueModel {
public $item_id;
public $object_id;
public $value_string;
public $value_int;
public $value_text;
public $changed_by;
public $changed;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new Workflowvalue();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Workflowvalue", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Workflowvalue($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Workflowvalue", "*");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Workflowvalue($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Workflowvalue", "*", "$where");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Workflowvalue($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Workflowvalue", "*", $where);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Workflowvalue($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
//var_dump($filter);exit;
if(array_key_exists("create_by", $filter)) {
$create_by = $filter['create_by'];
if(is_numeric($create_by)) {
$where .= " AND create_by=$create_by";
}
}
if(array_key_exists("changed_by", $filter)) {
$changed_by = $filter['changed_by'];
if(is_numeric($create_by)) {
$where .= " AND changed_by=$changed_by";
}
}
if(array_key_exists("item_id", $filter)) {
$item_id = $filter['item_id'];
if(is_numeric($item_id)) {
$where .= " AND item_id=$item_id";
}
}
if(array_key_exists("object_id", $filter)) {
$object_id = $filter['object_id'];
if(is_numeric($object_id)) {
$where .= " AND object_id=$object_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,37 @@
ALTER TABLE `Building` ADD `workflow_finished` INT NOT NULL DEFAULT '0' AFTER `networksection_id`;
CREATE TABLE `Workflowitem` (
`id` int NOT NULL AUTO_INCREMENT,
`num` int NOT NULL DEFAULT '0',
`object_type` enum('Building','Termination') COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'Building',
`active` int NOT NULL DEFAULT '1',
`visible` int NOT NULL DEFAULT '1',
`required` int NOT NULL DEFAULT '1',
`name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
`label` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL,
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci,
`type` enum('string','int','bool','enum','text','file','gps','color','delimiter') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'string',
`typedata` text COLLATE utf8mb4_unicode_520_ci,
`placeholder` varchar(1024) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE `Workflowvalue` (
`id` int NOT NULL AUTO_INCREMENT,
`item_id` int NOT NULL,
`object_id` int NOT NULL,
`value_string` varchar(1024) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`value_int` int DEFAULT NULL,
`value_text` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`changed_by` int NOT NULL,
`changed` int NOT NULL,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

View File

@@ -29,6 +29,10 @@
}
.building-list-tr {
cursor: pointer;
}
td.controls {
cursor: default;
text-align: left; letter-spacing: 4px; font-size: 1.1em;