Merge branch 'RMLWorkorder/v2-need-improvements' into 'master'

Rml workorder/v2 need improvements

See merge request fronk/thetool!1600
This commit is contained in:
Luca Haid
2025-08-05 07:05:33 +00:00
16 changed files with 1534 additions and 613 deletions

View File

@@ -5,26 +5,20 @@ class RMLWorkorderModel extends TTCrudBaseModel {
public int $id; public int $id;
public int $preorderId; public int $preorderId;
public ?int $companyId; public ?int $companyId;
public ?int $clusterId;
public string $status; public string $status;
public ?int $assignmentDate; public ?int $assignmentDate;
public ?int $deadlineDate; public ?int $deadlineDate;
public ?int $appointmentDate; public ?int $appointmentDate;
public int $create; public int $create;
public int $createBy; public int $createBy;
/** // This method remains unchanged as requested.
* Finds work orders that are nearing their deadline or are overdue.
* This can be used for the traffic light system.
*
* @param string $urgency 'red', 'yellow', or 'green'
* @return array
*/
public static function getWorkordersByUrgency(string $urgency, ?int $companyId = null): array { public static function getWorkordersByUrgency(string $urgency, ?int $companyId = null): array {
$db = self::getDB(); $db = self::getDB();
$table = self::getFullyQualifiedTable(); $table = self::getFullyQualifiedTable();
$now = time(); $whereClause = "WHERE status IN ('assigned', 'scheduled', 'correction_requested')";
$whereClause = "WHERE status IN ('assigned', 'scheduled')";
if ($companyId) { if ($companyId) {
$whereClause .= " AND companyId = " . intval($companyId); $whereClause .= " AND companyId = " . intval($companyId);
} }
@@ -32,7 +26,7 @@ class RMLWorkorderModel extends TTCrudBaseModel {
switch ($urgency) { switch ($urgency) {
case 'red': // Less than 1 week left or overdue case 'red': // Less than 1 week left or overdue
$redDate = strtotime('+1 week'); $redDate = strtotime('+1 week');
$whereClause .= " AND deadlineDate < $redDate"; $whereClause .= " AND deadlineDate IS NOT NULL AND deadlineDate < $redDate";
break; break;
case 'yellow': // Between 1 and 3 weeks left case 'yellow': // Between 1 and 3 weeks left
$yellowDateStart = strtotime('+1 week'); $yellowDateStart = strtotime('+1 week');
@@ -41,7 +35,7 @@ class RMLWorkorderModel extends TTCrudBaseModel {
break; break;
case 'green': // More than 3 weeks left case 'green': // More than 3 weeks left
$greenDate = strtotime('+3 weeks'); $greenDate = strtotime('+3 weeks');
$whereClause .= " AND deadlineDate > $greenDate"; $whereClause .= " AND deadlineDate > $greenDate";
break; break;
default: default:
return []; return [];
@@ -56,4 +50,192 @@ class RMLWorkorderModel extends TTCrudBaseModel {
return $orders; return $orders;
} }
// --- REFACTORED METHODS ---
private static function buildWhereClause(array $filters, array $allowedCampaignIds): string {
if (empty($allowedCampaignIds)) {
return " WHERE 1=0";
}
$sql = Helper::generateFilterCondition(array_map('intval', $allowedCampaignIds), 'p.preordercampaign_id');
if (!empty($filters['id'])) {
$sql .= Helper::generateFilterCondition($filters['id'], 'w.id', true);
}
if (!empty($filters['status'])) {
$sql .= Helper::generateFilterCondition($filters['status'], 'w.status', true);
}
if (!empty($filters['preordercampaign_id'])) {
$sql .= Helper::generateFilterCondition($filters['preordercampaign_id'], 'p.preordercampaign_id');
}
if (!empty($filters['companyName'])) {
$sql .= Helper::generateFilterCondition($filters['companyName'], 'c.name');
}
if (!empty($filters['deadlineDate'])) {
$sql .= Helper::generateFilterCondition($filters['deadlineDate'], 'w.deadlineDate');
}
if (!empty($filters['preorderInfo'])) {
$searchColumns = "p.firstname|p.lastname|p.company|p.oaid|p.street|p.housenumber|p.zip|p.city|str.name|ort.name";
$sql .= Helper::generateFilterCondition($filters['preorderInfo'], $searchColumns);
}
return "WHERE " . ltrim(trim($sql), 'AND');
}
public static function getAdminWorkorders(array $filters, ?int $limit, int $offset, array $order, array $allowedCampaignIds): array {
$db = self::getDB();
$fronkDbName = FRONKDB_DBNAME;
$addressDbName = defined('ADDRESSDB_DBNAME') ? ADDRESSDB_DBNAME : 'addressdb';
$sql = "
SELECT
w.id, w.status, w.deadlineDate, w.companyId, p.preordercampaign_id,
CONCAT_WS(' ', p.firstname, p.lastname) as customerName,
p.company as customerCompany, p.oaid, c.name as companyName,
str.name as street, hn.hausnummer, hn.stiege, we.bezeichner as apartment, plz.plz, ort.name as city
FROM `$fronkDbName`.`RMLWorkorder` w
JOIN `$fronkDbName`.`Preorder` p ON w.preorderId = p.id
LEFT JOIN `$fronkDbName`.`Preordercampaign` pc ON p.preordercampaign_id = pc.id
LEFT JOIN `$fronkDbName`.`RMLWorkorderCompany` c ON w.companyId = c.id
LEFT JOIN `$addressDbName`.`Hausnummer` hn ON p.adb_hausnummer_id = hn.id
LEFT JOIN `$addressDbName`.`Strasse` str ON hn.strasse_id = str.id
LEFT JOIN `$addressDbName`.`Plz` plz ON hn.plz_id = plz.id
LEFT JOIN `$addressDbName`.`Ortschaft` ort ON hn.ortschaft_id = ort.id
LEFT JOIN `$addressDbName`.`Wohneinheit` we ON p.adb_wohneinheit_id = we.id
";
$sql .= self::buildWhereClause($filters, $allowedCampaignIds);
$sql .= " ORDER BY CASE WHEN w.deadlineDate IS NULL THEN 1 ELSE 0 END, w.deadlineDate ASC";
if (!empty($order['key'])) {
$sortableColumns = ['id', 'status', 'deadlineDate', 'companyName', 'clusterName'];
if (in_array($order['key'], $sortableColumns)) {
$sortOrder = (strtoupper($order['order']) === 'DESC') ? 'DESC' : 'ASC';
$sql .= ", " . $db->real_escape_string($order['key']) . " " . $sortOrder;
}
}
if ($limit !== null) {
$sql .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
}
$result = $db->query($sql);
return $result ? $result->fetch_all(MYSQLI_ASSOC) : [];
}
public static function countAdminWorkorders(array $filters, array $allowedCampaignIds): int {
$db = self::getDB();
$fronkDbName = FRONKDB_DBNAME;
$addressDbName = defined('ADDRESSDB_DBNAME') ? ADDRESSDB_DBNAME : 'addressdb';
$sql = "
SELECT COUNT(w.id) as count
FROM `$fronkDbName`.`RMLWorkorder` w
JOIN `$fronkDbName`.`Preorder` p ON w.preorderId = p.id
LEFT JOIN `$fronkDbName`.`RMLWorkorderCompany` c ON w.companyId = c.id
LEFT JOIN `$addressDbName`.`Hausnummer` hn ON p.adb_hausnummer_id = hn.id
LEFT JOIN `$addressDbName`.`Strasse` str ON hn.strasse_id = str.id
LEFT JOIN `$addressDbName`.`Plz` plz ON hn.plz_id = plz.id
LEFT JOIN `$addressDbName`.`Ortschaft` ort ON hn.ortschaft_id = ort.id
";
$sql .= self::buildWhereClause($filters, $allowedCampaignIds);
$result = $db->query($sql);
if ($result === false) return 0;
$row = $result->fetch_assoc();
return $row['count'] ?? 0;
}
private static function buildCompanyWhereClause(array $filters, int $companyId): string
{
$sql = "w.companyId = " . $companyId;
if (!empty($filters['id'])) {
$sql .= Helper::generateFilterCondition($filters['id'], 'w.id', true);
}
if (!empty($filters['status'])) {
$sql .= Helper::generateFilterCondition($filters['status'], 'w.status');
}
if (!empty($filters['deadlineDate'])) {
$sql .= Helper::generateFilterCondition($filters['deadlineDate'], 'w.deadlineDate');
}
if (!empty($filters['appointmentDate'])) {
$sql .= Helper::generateFilterCondition($filters['appointmentDate'], 'w.appointmentDate');
}
if (!empty($filters['preorderInfo'])) {
$searchColumns = "p.firstname|p.lastname|p.company|p.oaid|p.street|p.housenumber|p.zip|p.city|str.name|ort.name|p.phone|p.email";
$sql .= Helper::generateFilterCondition($filters['preorderInfo'], $searchColumns);
}
return "WHERE " . $sql;
}
public static function getCompanyWorkorders(array $filters, ?int $limit, int $offset, array $order, int $companyId): array
{
$db = self::getDB();
$fronkDbName = FRONKDB_DBNAME;
$addressDbName = defined('ADDRESSDB_DBNAME') ? ADDRESSDB_DBNAME : 'addressdb';
$sql = "
SELECT
w.id, w.status, w.deadlineDate, w.appointmentDate,
CONCAT_WS(' ', p.firstname, p.lastname) as customerName,
p.company as customerCompany, p.oaid, p.phone, p.email,
str.name as street, hn.hausnummer, hn.stiege, we.bezeichner as apartment, plz.plz, ort.name as city
FROM `$fronkDbName`.`RMLWorkorder` w
JOIN `$fronkDbName`.`Preorder` p ON w.preorderId = p.id
LEFT JOIN `$addressDbName`.`Hausnummer` hn ON p.adb_hausnummer_id = hn.id
LEFT JOIN `$addressDbName`.`Strasse` str ON hn.strasse_id = str.id
LEFT JOIN `$addressDbName`.`Plz` plz ON hn.plz_id = plz.id
LEFT JOIN `$addressDbName`.`Ortschaft` ort ON hn.ortschaft_id = ort.id
LEFT JOIN `$addressDbName`.`Wohneinheit` we ON p.adb_wohneinheit_id = we.id
";
$sql .= self::buildCompanyWhereClause($filters, $companyId);
$orderBy = " ORDER BY CASE WHEN w.deadlineDate IS NULL THEN 1 ELSE 0 END, w.deadlineDate ASC";
if (!empty($order['key'])) {
$sortableColumns = ['id', 'status', 'deadlineDate', 'appointmentDate'];
if (in_array($order['key'], $sortableColumns)) {
$sortOrder = (strtoupper($order['order']) === 'DESC') ? 'DESC' : 'ASC';
$orderBy = " ORDER BY " . $db->real_escape_string($order['key']) . " " . $sortOrder;
}
}
$sql .= $orderBy;
if ($limit !== null) {
$sql .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
}
$result = $db->query($sql);
return $result ? $result->fetch_all(MYSQLI_ASSOC) : [];
}
public static function countCompanyWorkorders(array $filters, int $companyId): int
{
$db = self::getDB();
$fronkDbName = FRONKDB_DBNAME;
$addressDbName = defined('ADDRESSDB_DBNAME') ? ADDRESSDB_DBNAME : 'addressdb';
$sql = "
SELECT COUNT(w.id) as count
FROM `$fronkDbName`.`RMLWorkorder` w
JOIN `$fronkDbName`.`Preorder` p ON w.preorderId = p.id
LEFT JOIN `$addressDbName`.`Hausnummer` hn ON p.adb_hausnummer_id = hn.id
LEFT JOIN `$addressDbName`.`Strasse` str ON hn.strasse_id = str.id
LEFT JOIN `$addressDbName`.`Plz` plz ON hn.plz_id = plz.id
LEFT JOIN `$addressDbName`.`Ortschaft` ort ON hn.ortschaft_id = ort.id
";
$sql .= self::buildCompanyWhereClause($filters, $companyId);
$result = $db->query($sql);
if ($result === false) {
return 0;
}
$row = $result->fetch_assoc();
return $row['count'] ?? 0;
}
} }

View File

@@ -10,21 +10,27 @@ class RMLWorkorderAdminController extends TTCrud
protected array $columns = [ protected array $columns = [
['key' => 'id', 'text' => 'Auftrag-Nr.', 'table' => ['sortable' => true]], ['key' => 'id', 'text' => 'Auftrag-Nr.', 'table' => ['sortable' => true]],
['key' => 'preorderInfo', 'text' => 'Kunde / Projekt', 'modal' => false, 'table' => ['sortable' => false, 'filter' => 'search']], ['key' => 'preorderInfo', 'text' => 'Kunde / Projekt', 'modal' => false, 'table' => ['sortable' => false, 'filter' => 'search']],
['key' => 'preordercampaign_id', 'text' => 'Cluster', 'modal' => false, 'table' => ['filter' => 'select']],
['key' => 'companyName', 'text' => 'Zuständige Firma', 'modal' => false, 'table' => ['filter' => 'search']], ['key' => 'companyName', 'text' => 'Zuständige Firma', 'modal' => false, 'table' => ['filter' => 'search']],
['key' => 'status', 'text' => 'Status', 'modal' => false, 'table' => ['filter' => 'iconSelect', 'filterOptions' => [ ['key' => 'status', 'text' => 'Status', 'modal' => false, 'table' => ['filter' => 'iconSelect', 'filterOptions' => [
['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'], ['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'],
['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'], ['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'],
['value' => 'scheduled', 'text' => 'Terminiert', 'icon' => 'fas fa-calendar-check text-warning'], ['value' => 'scheduled', 'text' => 'Terminiert', 'icon' => 'fas fa-calendar-check text-warning'],
['value' => 'correction_requested', 'text' => 'Korrektur angefordert', 'icon' => 'fas fa-exclamation-triangle text-danger'],
['value' => 'documented', 'text' => 'Dokumentiert', 'icon' => 'fas fa-file-alt text-success'], ['value' => 'documented', 'text' => 'Dokumentiert', 'icon' => 'fas fa-file-alt text-success'],
['value' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'], ['value' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'],
]]], ]]],
['key' => 'deadlineDate', 'text' => 'Deadline', 'modal' => false, 'table' => ['filter' => 'date']], ['key' => 'deadlineDate', 'text' => 'Deadline', 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'appointmentDate', 'text' => 'Termin', 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'actions', 'text' => 'Aktionen', 'modal' => false, 'table' => ['filter' => false, 'sortable' => false]],
]; ];
protected function indexAction() protected function indexAction()
{ {
$campaigns = Helper::getPreorderCampaignFromUser($this->user, true);
$this->columns[array_search('preordercampaign_id', array_column($this->columns, 'key'))]['table']['filterOptions'] = array_map(
fn($c) => ['value' => $c->id, 'text' => $c->name],
$campaigns
);
$this->createWorkordersFromPreorders(); $this->createWorkordersFromPreorders();
Helper::renderVue($this, 'RMLWorkorderAdmin', $this->headerTitle, [ Helper::renderVue($this, 'RMLWorkorderAdmin', $this->headerTitle, [
"CRUD_CONFIG" => $this->getCrudConfig(), "CRUD_CONFIG" => $this->getCrudConfig(),
@@ -32,62 +38,50 @@ class RMLWorkorderAdminController extends TTCrud
]); ]);
} }
protected function getAction() protected function getAction() {
{
$json = json_decode(file_get_contents('php://input'), true); $json = json_decode(file_get_contents('php://input'), true);
$pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10]; $pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10];
$filters = $json['filters'] ?? []; $filters = $json['filters'] ?? [];
$order = $json['order'] ?? ['key' => 'id', 'order' => 'DESC']; $order = $json['order'] ?? [];
// Custom filter logic for preorderInfo $allowedCampaignIds = Helper::getPreorderCampaignFromUser($this->user);
if (!empty($filters['preorderInfo'])) {
$searchTerm = $filters['preorderInfo'];
unset($filters['preorderInfo']);
// This is a simplified search. A more robust implementation might involve a full-text search or a more complex query.
$preorders = PreorderModel::getAll(['firstname|lastname|company|oaid' => $searchTerm]);
$preorderIds = array_map(fn($p) => $p->id, $preorders);
if (!empty($preorderIds)) { if (empty($allowedCampaignIds)) {
$filters['preorderId'] = $preorderIds; self::returnJson([
} else { 'rows' => [],
// No preorders found, so no workorders will be found 'pagination' => array_merge($pagination, ['total_rows' => 0, 'total_pages' => 0, 'filtered_available' => 0])
$filters['id'] = -1; ]);
} return;
} }
$workorders = RMLWorkorderModel::getAll($filters, $pagination['per_page'], ($pagination['page'] - 1) * $pagination['per_page'], $order); $limit = $pagination['per_page'];
$totalCount = RMLWorkorderModel::count($filters); $offset = ($pagination['page'] - 1) * $limit;
$rows = []; $workorders = RMLWorkorderModel::getAdminWorkorders($filters, $limit, $offset, $order, $allowedCampaignIds);
foreach($workorders as $workorder) { $totalCount = RMLWorkorderModel::countAdminWorkorders($filters, $allowedCampaignIds);
$rows = array_map(function($workorder) {
$row = (array)$workorder; $row = (array)$workorder;
$preorder = new Preorder($workorder->preorderId);
$anschlussadresse = 'N/A';
if ($preorder->adb_hausnummer_id) {
$hn = $preorder->adb_hausnummer;
$anschlussadresse = "{$hn->strasse->name} {$hn->hausnummer}";
if ($hn->stiege) $anschlussadresse .= "/{$hn->stiege}";
if ($preorder->adb_wohneinheit_id) $anschlussadresse .= " / WE: {$preorder->adb_wohneinheit->bezeichner}";
$anschlussadresse .= ", {$hn->plz->plz} {$hn->ortschaft->name}";
}
$kunde = ($preorder->company) ?: "{$preorder->firstname} {$preorder->lastname}"; $anschlussadresse = "{$row['street']} {$row['hausnummer']}";
if ($row['stiege']) $anschlussadresse .= "/{$row['stiege']}";
if ($row['apartment']) $anschlussadresse .= " / WE: {$row['apartment']}";
$anschlussadresse .= ", {$row['plz']} {$row['city']}";
$kunde = $row['customerCompany'] ?: $row['customerName'];
$row['preorderInfo'] = "<strong>Kunde:</strong> {$kunde}<br>" . $row['preorderInfo'] = "<strong>Kunde:</strong> {$kunde}<br>" .
"<strong>Anschluss:</strong> {$anschlussadresse}<br>" . "<strong>Anschluss:</strong> {$anschlussadresse}<br>" .
"<strong>OAID:</strong> <span class='text-pink'>{$preorder->oaid}</span>"; "<strong>OAID:</strong> <span class='text-pink'>{$row['oaid']}</span>";
if($workorder->companyId) { $row['companyName'] ??= 'Nicht zugewiesen';
$company = RMLWorkorderCompanyModel::get($workorder->companyId); $row['deadlineDateFormatted'] = $row['deadlineDate'] ? date('d.m.Y', $row['deadlineDate']) : 'Keine Deadline';
$row['companyName'] = $company->name ?? 'N/A'; $row['daysUntilDeadline'] = $row['deadlineDate'] ? ceil(($row['deadlineDate'] - time()) / (60 * 60 * 24)) : null;
} else {
$row['companyName'] = 'Nicht zugewiesen'; unset($row['customerName'], $row['customerCompany'], $row['street'], $row['hausnummer'], $row['stiege'], $row['oaid'], $row['apartment'], $row['plz'], $row['city']);
}
return $row;
$rows[] = $row; }, $workorders);
}
self::returnJson([ self::returnJson([
'rows' => $rows, 'rows' => $rows,
@@ -95,7 +89,7 @@ class RMLWorkorderAdminController extends TTCrud
'page' => $pagination['page'], 'page' => $pagination['page'],
'per_page' => $pagination['per_page'], 'per_page' => $pagination['per_page'],
'total_rows' => $totalCount, 'total_rows' => $totalCount,
'total_pages' => ceil($totalCount / $pagination['per_page']), 'total_pages' => ceil($totalCount / $limit),
'filtered_available' => $totalCount 'filtered_available' => $totalCount
] ]
]); ]);
@@ -109,6 +103,7 @@ class RMLWorkorderAdminController extends TTCrud
if (!RMLWorkorderModel::getFirst(['preorderId' => $preorder->id])) { if (!RMLWorkorderModel::getFirst(['preorderId' => $preorder->id])) {
RMLWorkorderModel::create([ RMLWorkorderModel::create([
'preorderId' => $preorder->id, 'preorderId' => $preorder->id,
'clusterId' => $preorder->preordercampaign_id,
'status' => 'new', 'status' => 'new',
'create' => time(), 'create' => time(),
'createBy' => $this->user->id 'createBy' => $this->user->id
@@ -123,35 +118,112 @@ class RMLWorkorderAdminController extends TTCrud
$workorder = RMLWorkorderModel::get($post['workorderId']); $workorder = RMLWorkorderModel::get($post['workorderId']);
if (!$workorder) self::sendError("Workorder not found."); if (!$workorder) self::sendError("Workorder not found.");
$workorder->companyId = $post['companyId']; $workorder->companyId = $post['companyId'];
$workorder->status = 'assigned'; $workorder->status = 'assigned';
$workorder->assignmentDate = time(); $workorder->assignmentDate = time();
$workorder->deadlineDate = strtotime('+6 weeks'); $workorder->deadlineDate = $post['deadlineDate'] ?? strtotime('+6 weeks');
RMLWorkorderModel::update((array)$workorder); RMLWorkorderModel::update((array)$workorder);
self::returnJson(['success' => true, 'message' => 'Auftrag erfolgreich zugewiesen.']); self::returnJson(['success' => true, 'message' => 'Auftrag erfolgreich zugewiesen.']);
} }
protected function getDocumentationAction() { protected function getDocumentationAction() {
if(empty($this->request->workorderId)) self::sendError("Workorder ID missing."); if(empty($this->request->workorderId)) self::sendError("Workorder ID missing.");
$docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC']); $docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC']);
$users = UserModel::search(['employee' => true]); $journals = RMLWorkorderJournalModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC']);
$userMap = array_reduce($users, fn($carry, $user) => $carry + [$user->id => $user->name], []); $users = UserModel::search();
foreach($docs as $doc) { foreach($docs as $doc) {
$file = new File($doc->fileId); $file = new File($doc->fileId);
$doc->fileName = $file->orig_filename ?? $file->filename; $doc->fileName = $file->orig_filename ?? $file->filename;
$doc->userName = $userMap[$doc->createBy] ?? 'Unbekannt'; $doc->userName = UserModel::getOne($doc->createBy)->name ?? 'Unbekannt';
$doc->mimetype = $file->mimetype ?? 'application/octet-stream';
} }
self::returnJson($docs); foreach($journals as $journal) {
$journal->createByName = UserModel::getOne($journal->createBy)->name ?? 'Unbekannt';
}
self::returnJson(['docs' => $docs, 'journals' => $journals]);
} }
protected function massAssignWorkordersAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['workorderIds']) || empty($post['companyId'])) self::sendError("Required fields are missing.");
$deadline = strtotime($post['deadlineDate'] ?? '+6 weeks');
$count = 0;
foreach ($post['workorderIds'] as $workorderId) {
$workorder = RMLWorkorderModel::get($workorderId);
if ($workorder && $workorder->status === 'new') {
$workorder->companyId = $post['companyId'];
$workorder->status = 'assigned';
$workorder->assignmentDate = time();
$workorder->deadlineDate = $deadline;
RMLWorkorderModel::update((array)$workorder);
$count++;
}
}
self::returnJson(['success' => true, 'message' => "$count Aufträge erfolgreich zugewiesen."]);
}
protected function requestCorrectionAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['workorderId']) || empty($post['text'])) self::sendError("Required fields are missing.");
$workorder = RMLWorkorderModel::get($post['workorderId']);
if (!$workorder) self::sendError("Workorder not found.");
$oldStatus = $workorder->status;
$workorder->status = 'correction_requested';
RMLWorkorderModel::update((array)$workorder);
RMLWorkorderJournalModel::create([
'workorderId' => $workorder->id,
'text' => $post['text'],
'fileIds' => !empty($post['fileIds']) ? json_encode($post['fileIds']) : null,
'statusChange' => "$oldStatus -> correction_requested",
'create' => time(),
'createBy' => $this->user->id,
]);
self::returnJson(['success' => true, 'message' => 'Korrektur wurde angefordert.']);
}
protected function getCompaniesAction() { protected function getCompaniesAction() {
$companies = RMLWorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']); $companies = RMLWorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
$items = array_map(fn($c) => ['value' => $c->id, 'text' => $c->name], $companies); $items = array_map(fn($c) => ['value' => $c->id, 'text' => $c->name], $companies);
self::returnJson($items); self::returnJson($items);
} }
protected function addJournalAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['workorderId']) || empty(trim($post['text']))) {
self::sendError("Workorder ID and text are required.");
}
RMLWorkorderJournalModel::create([
'workorderId' => $post['workorderId'],
'text' => $post['text'],
'createBy' => $this->user->id,
'create' => time(),
]);
$journals = array_map(
function ($j) {
$j->createByName = UserModel::getOne($j->createBy)->name ?? 'Unbekannt';
return (array)$j;
},
RMLWorkorderJournalModel::getAll(['workorderId' => $post['workorderId']], null, 0, ['key' => 'create', 'order' => 'DESC'])
);
self::returnJson([
'success' => true,
'message' => 'Journal-Eintrag hinzugefügt.',
'journals' => $journals
]);
}
} }

View File

@@ -13,12 +13,12 @@ class RMLWorkorderCompanyController extends TTCrud
['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'], ['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'],
['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'], ['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'],
['value' => 'scheduled', 'text' => 'Terminiert', 'icon' => 'fas fa-calendar-check text-warning'], ['value' => 'scheduled', 'text' => 'Terminiert', 'icon' => 'fas fa-calendar-check text-warning'],
['value' => 'correction_requested', 'text' => 'Korrektur angefordert', 'icon' => 'fas fa-exclamation-triangle text-danger'],
['value' => 'documented', 'text' => 'Dokumentiert', 'icon' => 'fas fa-file-alt text-success'], ['value' => 'documented', 'text' => 'Dokumentiert', 'icon' => 'fas fa-file-alt text-success'],
['value' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'], ['value' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'],
]]], ]]],
['key' => 'deadlineDate', 'text' => 'Deadline', 'modal' => false, 'table' => ['filter' => 'date']], ['key' => 'deadlineDate', 'text' => 'Deadline', 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'appointmentDate', 'text' => 'Termin', 'modal' => false, 'table' => ['filter' => 'date']], ['key' => 'appointmentDate', 'text' => 'Termin', 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'actions', 'text' => 'Aktionen', 'modal' => false, 'table' => ['filter' => false, 'sortable' => false]],
]; ];
protected array $additionalJSVariables = ['COMPANY_ID' => '0']; protected array $additionalJSVariables = ['COMPANY_ID' => '0'];
@@ -46,40 +46,38 @@ class RMLWorkorderCompanyController extends TTCrud
$json = json_decode(file_get_contents('php://input'), true); $json = json_decode(file_get_contents('php://input'), true);
$pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10]; $pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10];
$filters = $json['filters'] ?? []; $filters = $json['filters'] ?? [];
$order = $json['order'] ?? ['key' => 'id', 'order' => 'DESC']; $order = $json['order'] ?? ['key' => 'deadlineDate', 'order' => 'ASC'];
$company = RMLWorkorderCompanyModel::getFirst(['addressId' => $this->user->address_id]); $company = RMLWorkorderCompanyModel::getFirst(['addressId' => $this->user->address_id]);
if(!$company) self::sendError("Company not found for user.", 403); if (!$company) {
$filters['companyId'] = $company->id; self::sendError("Company not found for user.", 403);
if (!empty($filters['preorderInfo'])) {
$searchTerm = $filters['preorderInfo'];
//todo: fix this preordermodel search shit
$preorders = PreorderModel::getAll(['firstname|lastname|company|oaid' => $searchTerm]);
$preorderIds = array_map(fn($p) => $p->id, $preorders);
if (!empty($preorderIds)) {
$filters['preorderId'] = $preorderIds;
} else {
$filters['id'] = -1;
}
} }
unset($filters['preorderInfo']);
// only show workorders that are assigned to the company and have the status assigned or scheduled
$filters['status'] = ['assigned', 'scheduled'];
$filters['companyId'] = $company->id;
// Get paginated workorders and total count from the new model methods
$workorders = RMLWorkorderModel::getCompanyWorkorders($filters, $pagination['per_page'], ($pagination['page'] - 1) * $pagination['per_page'], $order, $company->id);
$totalCount = RMLWorkorderModel::countCompanyWorkorders($filters, $company->id);
$workorders = RMLWorkorderModel::getAll($filters, $pagination['per_page'], ($pagination['page'] - 1) * $pagination['per_page'], $order); // Format rows for the frontend
$totalCount = RMLWorkorderModel::count($filters); $rows = array_map(function($workorder) {
$rows = [];
foreach($workorders as $workorder) {
$row = (array)$workorder; $row = (array)$workorder;
$row['preorderInfo'] = $this->getPreorderInfoText($workorder->preorderId);
$rows[] = $row; $anschlussadresse = "{$row['street']} {$row['hausnummer']}";
} if ($row['stiege']) $anschlussadresse .= "/{$row['stiege']}";
if ($row['apartment']) $anschlussadresse .= " / WE: {$row['apartment']}";
$anschlussadresse .= ", {$row['plz']} {$row['city']}";
$kunde = $row['customerCompany'] ?: $row['customerName'];
$row['preorderInfo'] = "<strong>Kunde:</strong> {$kunde}<br>" .
"<strong>Anschluss:</strong> {$anschlussadresse}<br>" .
"<strong>Kontakt:</strong> {$row['phone']} / {$row['email']}<br>" .
"<strong>OAID:</strong> <span class='text-pink'>{$row['oaid']}</span>";
// Clean up unnecessary fields before sending
unset($row['customerName'], $row['customerCompany'], $row['street'], $row['hausnummer'], $row['stiege'], $row['oaid'], $row['apartment'], $row['plz'], $row['city'], $row['phone'], $row['email']);
return $row;
}, $workorders);
self::returnJson([ self::returnJson([
'rows' => $rows, 'rows' => $rows,
@@ -92,7 +90,6 @@ class RMLWorkorderCompanyController extends TTCrud
] ]
]); ]);
} }
public function getWorkorderByIdAction() { public function getWorkorderByIdAction() {
$id = $this->request->id; $id = $this->request->id;
if(!$id) self::sendError("ID missing"); if(!$id) self::sendError("ID missing");
@@ -173,22 +170,30 @@ class RMLWorkorderCompanyController extends TTCrud
]); ]);
$uploadCount++; $uploadCount++;
} catch (Exception $e) { } catch (Exception $e) {
var_dump($e->getMessage());exit;
// Log error but continue with other files
error_log("File upload failed for $name: " . $e->getMessage()); error_log("File upload failed for $name: " . $e->getMessage());
} }
} }
} }
self::returnJson(['success' => true, 'message' => "$uploadCount Datei(en) erfolgreich hochgeladen."]); $workorder = RMLWorkorderModel::get($workorderId);
if ($workorder->status === 'correction_requested') {
$workorder->status = 'assigned';
RMLWorkorderModel::update((array)$workorder);
$workorder = RMLWorkorderModel::get($workorderId);
}
$formattedDocs = $this->getFormattedDocs($workorderId);
self::returnJson([
'success' => true,
'message' => "$uploadCount Datei(en) erfolgreich hochgeladen.",
'docs' => $formattedDocs,
'workorder' => (array)$workorder
]);
} }
protected function getDocumentationAction() { private function getFormattedDocs($workorderId) {
if(empty($this->request->workorderId)) self::sendError("Workorder ID missing."); $docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $workorderId], null, 0, ['key' => 'create', 'order' => 'ASC']);
// Order by creation date to ensure consistent numbering (_1, _2, etc.)
$docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'ASC']);
$responseDocs = []; $responseDocs = [];
$typeCounts = []; $typeCounts = [];
@@ -202,8 +207,6 @@ class RMLWorkorderCompanyController extends TTCrud
foreach($docs as $doc) { foreach($docs as $doc) {
$file = new File($doc->fileId); $file = new File($doc->fileId);
// Increment counter for the specific document type
$documentTypeKey = $doc->documentType; $documentTypeKey = $doc->documentType;
if (!isset($typeCounts[$documentTypeKey])) { if (!isset($typeCounts[$documentTypeKey])) {
$typeCounts[$documentTypeKey] = 1; $typeCounts[$documentTypeKey] = 1;
@@ -211,23 +214,37 @@ class RMLWorkorderCompanyController extends TTCrud
$typeCounts[$documentTypeKey]++; $typeCounts[$documentTypeKey]++;
} }
// Construct the new filename using the original key
$originalFilename = $file->orig_filename ?? $file->filename; $originalFilename = $file->orig_filename ?? $file->filename;
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION); $extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$translatedType = $translationMap[$documentTypeKey] ?? $documentTypeKey; $translatedType = $translationMap[$documentTypeKey] ?? $documentTypeKey;
$newFilename = "{$translatedType} {$typeCounts[$documentTypeKey]}." . strtolower($extension); $newFilename = "{$translatedType}_{$typeCounts[$documentTypeKey]}." . strtolower($extension);
// Get the translated text, with a fallback to the original key
// Build the response object with 'id' mapped from 'fileId' and the translated type
$responseDocs[] = [ $responseDocs[] = [
'id' => $doc->fileId, 'id' => $doc->id,
'fileId' => $doc->fileId,
'fileName' => $newFilename, 'fileName' => $newFilename,
'documentType' => $documentTypeKey, 'documentType' => $documentTypeKey,
'mimetype' => $file->mimetype, 'mimetype' => $file->mimetype,
]; ];
} }
self::returnJson($responseDocs); return $responseDocs;
}
protected function getDocumentationAction() {
if(empty($this->request->workorderId)) self::sendError("Workorder ID missing.");
$docs = $this->getFormattedDocs($this->request->workorderId);
$journals = array_map(
function ($j) {
$j->createByName = UserModel::getOne($j->createBy)->getAbbrName();
return (array)$j;
},
RMLWorkorderJournalModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC'])
);
self::returnJson(['docs' => $docs, 'journals' => $journals]);
} }
protected function completeWorkorderAction() { protected function completeWorkorderAction() {
$post = json_decode(file_get_contents('php://input'), true); $post = json_decode(file_get_contents('php://input'), true);
@@ -241,4 +258,74 @@ class RMLWorkorderCompanyController extends TTCrud
self::returnJson(['success' => true, 'message' => 'Auftrag abgeschlossen.']); self::returnJson(['success' => true, 'message' => 'Auftrag abgeschlossen.']);
} }
protected function deleteDocumentationAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['id'])) self::sendError("Document ID missing.");
$doc = RMLWorkorderDocumentationModel::get($post['id']);
if (!$doc) self::sendError("Document not found.");
$workorderId = $doc->workorderId;
RMLWorkorderDocumentationModel::delete($post['id']);
$formattedDocs = $this->getFormattedDocs($workorderId);
self::returnJson([
'success' => true,
'message' => 'Dokument gelöscht.',
'docs' => $formattedDocs
]);
}
protected function updateDocumentationAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['id'])) self::sendError("Document ID missing.");
$doc = RMLWorkorderDocumentationModel::get($post['id']);
if (!$doc) self::sendError("Dokument nicht gefunden.");
if (isset($post['documentType'])) {
$doc->documentType = $post['documentType'];
}
RMLWorkorderDocumentationModel::update((array)$doc);
$formattedDocs = $this->getFormattedDocs($doc->workorderId);
self::returnJson([
'success' => true,
'message' => 'Dokument aktualisiert.',
'docs' => $formattedDocs
]);
}
protected function addJournalAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['workorderId']) || empty(trim($post['text']))) {
self::sendError("Workorder ID and text are required.");
}
RMLWorkorderJournalModel::create([
'workorderId' => $post['workorderId'],
'text' => $post['text'],
'createBy' => $this->user->id,
'create' => time(),
]);
$journals = array_map(
function ($j) {
$j->createByName = UserModel::getOne($j->createBy)->getAbbrName();
return (array)$j;
},
RMLWorkorderJournalModel::getAll(['workorderId' => $post['workorderId']], null, 0, ['key' => 'create', 'order' => 'DESC'])
);
self::returnJson([
'success' => true,
'message' => 'Journal-Eintrag hinzugefügt.',
'journals' => $journals
]);
}
} }

View File

@@ -0,0 +1,11 @@
<?php
class RMLWorkorderJournalModel extends TTCrudBaseModel {
public int $id;
public int $workorderId;
public ?string $text;
public ?string $fileIds;
public ?string $statusChange;
public int $create;
public int $createBy;
}

View File

@@ -0,0 +1,14 @@
-- migration.sql
ALTER TABLE `RMLWorkorder` ADD `clusterId` INT NULL AFTER `companyId`;
CREATE TABLE `RMLWorkorderJournal` (
`id` int NOT NULL AUTO_INCREMENT,
`workorderId` int NOT NULL,
`text` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`fileIds` json DEFAULT NULL,
`statusChange` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`create` int NOT NULL,
`createBy` int NOT NULL,
PRIMARY KEY (`id`),
KEY `workorderId` (`workorderId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View File

@@ -11,49 +11,75 @@ class Helper {
public static function generateFilterCondition($filterValue, $columnName, bool $exactMatch = false): string { public static function generateFilterCondition($filterValue, $columnName, bool $exactMatch = false): string {
$sql = ""; $sql = "";
$quotedColumn = (strpos($columnName, '.') === false && strpos($columnName, '|') === false)
? "`$columnName`"
: $columnName;
if (is_array($filterValue)) { if (is_array($filterValue)) {
if (isset($filterValue['from']) && isset($filterValue['to'])) { if (isset($filterValue['from']) && isset($filterValue['to'])) {
$sql = " AND `$columnName` >= " . $filterValue['from'] . " AND `$columnName` <= " . $filterValue['to']; $sql = " AND $quotedColumn >= " . $filterValue['from'] . " AND $quotedColumn <= " . $filterValue['to'];
} elseif (isset($filterValue['from'])) { } elseif (isset($filterValue['from'])) {
$sql = " AND `$columnName` >= " . $filterValue['from']; $sql = " AND $quotedColumn >= " . $filterValue['from'];
} elseif (isset($filterValue['to'])) { } elseif (isset($filterValue['to'])) {
$sql = " AND `$columnName` <= " . $filterValue['to']; $sql = " AND $quotedColumn <= " . $filterValue['to'];
} else if (isset($filterValue['exact'])) { } else if (isset($filterValue['exact'])) {
$sql = " AND `$columnName` = " . "'{$filterValue['exact']}'"; $sql = " AND $quotedColumn = " . "'{$filterValue['exact']}'";
} else if (!empty($filterValue)) { } else if (!empty($filterValue)) {
$sql = " AND `$columnName` IN ('" . implode("','", $filterValue) . "')"; $sql = " AND $quotedColumn IN ('" . implode("','", $filterValue) . "')";
} }
} else if ($filterValue === "0" || $filterValue === "1") { } else if ($filterValue === "0" || $filterValue === "1") {
$sql .= " AND `$columnName` = " . $filterValue; $sql .= " AND $quotedColumn = " . $filterValue;
} else if ($filterValue === null) { } else if ($filterValue === null) {
$sql .= " AND `$columnName` IS NULL"; $sql .= " AND $quotedColumn IS NULL";
} else if ($filterValue === '!NULL') { } else if ($filterValue === '!NULL') {
$sql .= " AND `$columnName` IS NOT NULL"; $sql .= " AND $quotedColumn IS NOT NULL";
} else if (!empty($filterValue)) { } else if (!empty($filterValue)) {
if ($exactMatch) { if ($exactMatch) {
$sql .= " AND `$columnName` = '" . $filterValue . "'"; $sql .= " AND $quotedColumn = '" . $filterValue . "'";
} else if (strpos($columnName, "|") !== false) { } else if (strpos($columnName, "|") !== false) {
foreach (explode(" ", $filterValue) as $item) $columns = explode("|", $columnName);
$sql .= " AND CONCAT(" . join(",", explode("|", $columnName)) . ") LIKE '%" . $item . "%'";
// Loop through each search term (e.g., "john", "doe")
foreach (explode(" ", $filterValue) as $item) {
// Skip if the item is empty
if (empty(trim($item))) {
continue;
}
$escapedItem = addslashes($item); // Basic escaping
// Build the list of OR conditions for the current item
$orConditions = [];
foreach ($columns as $column) {
// e.g., "first_name LIKE '%john%'"
$orConditions[] = "$column LIKE '%" . $escapedItem . "%'";
}
// Combine the OR conditions into a single block and add to the query
// e.g., "AND (first_name LIKE '%john%' OR last_name LIKE '%john%')"
if (!empty($orConditions)) {
$sql .= " AND (" . implode(" OR ", $orConditions) . ")";
}
}
} else if ($filterValue[0] === "%") { } else if ($filterValue[0] === "%") {
$sql .= " AND `$columnName` LIKE '" . $filterValue . "'"; $sql .= " AND $quotedColumn LIKE '" . addslashes($filterValue) . "'";
} else if ($filterValue[strlen($filterValue) - 1] === "%") { } else if ($filterValue[strlen($filterValue) - 1] === "%") {
$sql .= " AND `$columnName` LIKE '" . $filterValue . "'"; $sql .= " AND $quotedColumn LIKE '" . addslashes($filterValue) . "'";
} else if ($filterValue[0] === "!") { } else if ($filterValue[0] === "!") {
$sql .= " AND `$columnName` NOT LIKE '%" . substr($filterValue, 1) . "%'"; $sql .= " AND $quotedColumn NOT LIKE '%" . addslashes(substr($filterValue, 1)) . "%'";
} else { } else {
$filterItems = explode(" ", $filterValue); $filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) { foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'"; $escapedItem = addslashes($item); // Basic escaping
$sql .= " AND $quotedColumn LIKE '%" . $escapedItem . "%'";
} }
} }
} else if ($filterValue === 0) { } else if ($filterValue === 0) {
$sql .= " AND `$columnName` = 0"; $sql .= " AND $quotedColumn = 0";
} }
return $sql; return $sql;
} }
/** /**
* Validates an array of data based on a set of predefined rules. * Validates an array of data based on a set of predefined rules.
* *
@@ -175,4 +201,16 @@ class Helper {
return number_format($number, $decimals, $decPoint, $thousandsSep); return number_format($number, $decimals, $decPoint, $thousandsSep);
} }
public static function getPreorderCampaignFromUser($user, bool $returnObject = false): array {
if ($user->isAdmin()) $campaigns = PreordercampaignModel::getAll();
else {
$networkIDs = array_unique(array_merge(
array_column($user->myNetworks(["netowner", "salespartner"]), 'id'),
json_decode($user->getFlag("preorder_networks")->value() ?: '[]')
));
$campaigns = PreordercampaignModel::search(['network_id' => $networkIDs]);
}
return $returnObject ? $campaigns : array_column($campaigns, 'id');
}
} }

View File

@@ -0,0 +1,27 @@
/*
* CSS for Workorder Table Row Highlighting (Balanced Colors)
*/
/* 🔴 Urgent: Deadline passed or less than 1 week away */
.table-hover .tt-rml-workorder-urgent:hover,
.tt-rml-workorder-urgent {
background-color: #f8d7da !important; /* Balanced Red */
}
/* 🟡 Medium: Deadline less than 3 weeks away */
.table-hover .tt-rml-workorder-medium:hover,
.tt-rml-workorder-medium {
background-color: #fff3cd !important; /* Balanced Yellow */
}
/* 🟢 On Track: Deadline more than 3 weeks away */
.table-hover .tt-rml-workorder-ontrack:hover,
.tt-rml-workorder-ontrack {
background-color: #d4edda !important; /* Balanced Green */
}
/* ⚫ Irrelevant: No deadline or status makes it not applicable */
.table-hover .tt-rml-workorder-irrelevant:hover,
.tt-rml-workorder-irrelevant {
background-color: #e9ecef !important; /* Balanced Grey */
}

View File

@@ -1,70 +1,151 @@
// RMLWorkorderAdmin.js // RMLWorkorderAdmin.js
Vue.component('r-m-l-workorder-admin', { Vue.component('r-m-l-workorder-admin', {
template: ` template: `
<tt-card> <tt-card>
<assign-company-modal <div class="mb-2 d-flex align-items-center" v-if="workordersToAssign.length > 0">
v-if="assignModalWorkorderId" <span class="mr-3 font-weight-bold">{{ workordersToAssign.length }} Workorder(s) zuweisen:</span>
:workorder-id="assignModalWorkorderId" <div style="width: 300px;">
@close="assignModalWorkorderId = null; $refs.table.$refs.table.refreshTable()" <tt-select
class="mb-0"
:options="companies"
v-model="massAssignCompanyId"
@input="massAssignCompanies"
placeholder="Firma auswählen..."
sm
no-form-group
/> />
</div>
<documentation-viewer-modal </div>
v-if="docsModalWorkorderId"
:workorder-id="docsModalWorkorderId" <tt-table-crud
@close="docsModalWorkorderId = null" ref="table"
:crud-config="crudConfig"
>
<template v-slot:preorderinfo="{ row }">
<div v-html="row.preorderInfo" class="small"></div>
</template>
<template v-slot:status="{ row }">
<traffic-light :deadline="row.deadlineDate" :status="row.status"/>
<i :class="getStatusColumn(row.status).icon" :title="getStatusColumn(row.status).text"></i>
<span class="ml-2">{{ getStatusColumn(row.status).text }}</span>
</template>
<template v-slot:companyname="{ row }">
<div class="d-flex justify-content-between align-items-center">
<div class="flex-grow-1">
<div v-if="editingWorkorderId === row.id">
<tt-select
:options="companies"
:value="row.companyId"
@input="assignCompany(row, $event)"
@blur="editingWorkorderId = null"
@keydown.esc.native="editingWorkorderId = null"
placeholder="Firma zuweisen..."
sm
no-form-group
/>
</div>
<div v-else-if="row.status === 'new'">
<tt-select
:options="companies"
:value="row.companyId"
@input="assignCompany(row, $event)"
placeholder="Firma zuweisen..."
sm
no-form-group
/>
</div>
<div v-else class="d-flex align-items-center">
<span>{{ row.companyName || 'N/A' }}</span>
<tt-button
icon="fas fa-edit"
@click="editingWorkorderId = row.id"
additional-class="btn-link btn-sm p-0 ml-2"
title="Zuweisung ändern"
/>
</div>
</div>
<div class="ml-3">
<tt-button v-if="!workordersToAssign.includes(row.id)"
icon="fas fa-plus-circle text-success"
@click="addToAssignList(row)"
additional-class="btn-link btn-sm p-0"
title="Zur Zuweisungsliste hinzufügen"
/>
<tt-button v-if="workordersToAssign.includes(row.id)"
icon="fas fa-minus-circle text-danger"
@click="removeFromAssignList(row)"
additional-class="btn-link btn-sm p-0"
title="Von Zuweisungsliste entfernen"
/>
</div>
</div>
</template>
<template v-slot:deadlinedate="{ row }">
{{ formatDate(row.deadlineDate) }}
<span v-if="row.daysUntilDeadline !== null && row.daysUntilDeadline >= 0" class="ml-2 text-muted small">
bis zum Termin: {{ row.daysUntilDeadline }} Tag{{ row.daysUntilDeadline !== 1 ? 'e' : '' }}
</span>
</template>
<template v-slot:appointmentdate="{ row }">
{{ formatDate(row.appointmentDate) }}
</template>
<template v-slot:expandedRow="{ row }">
<rml-documentation-viewer-admin
:workorder-id="row.id"
@workorder-updated="$refs.table.$refs.table.refreshTable()"
/> />
</template>
<tt-table-crud
ref="table"
@assign="assignModalWorkorderId = $event.id"
@view_docs="docsModalWorkorderId = $event.id"
:crud-config="crudConfig"
>
<template v-slot:preorderinfo="{ row }">
<div v-html="row.preorderInfo" class="small"></div>
</template>
<template v-slot:status="{ row }"> </tt-table-crud>
<traffic-light :deadline="row.deadlineDate" :status="row.status" /> </tt-card>
<i :class="getStatusColumn(row.status).icon" :title="getStatusColumn(row.status).text"></i>
<span class="ml-2">{{ getStatusColumn(row.status).text }}</span>
</template>
<template v-slot:deadlinedate="{ row }">
{{ formatDate(row.deadlineDate) }}
</template>
<template v-slot:appointmentdate="{ row }">
{{ formatDate(row.appointmentDate) }}
</template>
</tt-table-crud>
</tt-card>
`, `,
data() { data() {
return { return {
assignModalWorkorderId: null, workordersToAssign: [],
docsModalWorkorderId: null, editingWorkorderId: null,
companies: [],
massAssignCompanyId: null,
massAssignLoading: false,
crudConfig: { crudConfig: {
...window.TT_CONFIG.CRUD_CONFIG, ...window.TT_CONFIG.CRUD_CONFIG,
additionalActions: [ selectable: false,
{ expandable: true,
"key": "assign", customRowClass: (row) => {
"title": "Firma zuweisen", const deadlineDate = moment.unix(row.deadlineDate);
"class": "fas fa-user-plus text-primary",
"condition": (row) => row.status === 'new', if (['completed', 'new'].includes(row.status) || !deadlineDate.isValid()) {
}, return 'tt-rml-workorder-irrelevant';
{ }
"key": "view_docs",
"title": "Dokumentation ansehen", const daysLeft = deadlineDate.diff(moment(), 'days');
"class": "fas fa-folder-open text-info",
"condition": (row) => ['documented', 'completed'].includes(row.status), if (daysLeft <= 7) return 'tt-rml-workorder-urgent';
}, if (daysLeft <= 21) return 'tt-rml-workorder-medium';
]
return 'tt-rml-workorder-ontrack';
},
additionalActions: []
} }
} }
}, },
async mounted() {
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getCompanies`);
this.companies = response.data;
},
methods: { methods: {
addToAssignList(row) {
if (!this.workordersToAssign.includes(row.id)) {
this.workordersToAssign.push(row.id);
}
},
removeFromAssignList(row) {
this.workordersToAssign = this.workordersToAssign.filter(id => id !== row.id);
},
getStatusColumn(status) { getStatusColumn(status) {
const column = this.crudConfig.columns.find(c => c.key === 'status'); const column = this.crudConfig.columns.find(c => c.key === 'status');
return column.table.filterOptions.find(opt => opt.value === status) || {}; return column.table.filterOptions.find(opt => opt.value === status) || {};
@@ -72,6 +153,60 @@ Vue.component('r-m-l-workorder-admin', {
formatDate(timestamp) { formatDate(timestamp) {
if (!timestamp) return ''; if (!timestamp) return '';
return window.moment.unix(timestamp).format('DD.MM.YYYY'); return window.moment.unix(timestamp).format('DD.MM.YYYY');
},
async assignCompany(workorder, companyId) {
if (!companyId) {
this.editingWorkorderId = null;
return;
}
const payload = {
workorderId: workorder.id,
companyId: companyId
};
try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/assignWorkorder`, payload);
if (response.data.success) {
window.notify('success', response.data.message);
this.$refs.table.$refs.table.refreshTable();
} else {
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.');
}
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.editingWorkorderId = null;
}
},
async massAssignCompanies(companyId) {
if (!companyId) return;
if (!confirm(`${this.workordersToAssign.length} Workorder(s) der ausgewählten Firma zuweisen?`)) {
this.massAssignCompanyId = null; // Reset select on cancel
return;
}
this.massAssignLoading = true;
const payload = {
companyId: companyId,
workorderIds: this.workordersToAssign
};
try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/massAssignWorkorders`, payload);
if (response.data.success) {
window.notify('success', response.data.message);
this.workordersToAssign = [];
this.$refs.table.$refs.table.refreshTable();
} else {
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.');
}
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.massAssignLoading = false;
this.massAssignCompanyId = null;
}
} }
} }
}); });
@@ -80,104 +215,158 @@ Vue.component('traffic-light', {
props: ['deadline', 'status'], props: ['deadline', 'status'],
computed: { computed: {
lightInfo() { lightInfo() {
if (['completed', 'new'].includes(this.status)) return { color: '#cccccc', title: 'Status irrelevant für Dringlichkeit' }; if (['completed', 'new'].includes(this.status)) return {color: '#cccccc', title: 'Status irrelevant für Dringlichkeit'};
const now = moment(); const now = moment();
const deadlineDate = moment.unix(this.deadline); const deadlineDate = moment.unix(this.deadline);
if (!deadlineDate.isValid()) return { color: '#cccccc', title: 'Keine Deadline gesetzt' }; if (!deadlineDate.isValid()) return {color: '#cccccc', title: 'Keine Deadline gesetzt'};
if (deadlineDate.isBefore(now)) return { color: '#dc3545', title: 'Deadline überschritten' }; if (deadlineDate.isBefore(now)) return {color: '#dc3545', title: 'Deadline überschritten'};
const daysLeft = deadlineDate.diff(now, 'days'); const daysLeft = deadlineDate.diff(now, 'days');
if (daysLeft <= 7) return { color: '#dc3545', title: 'Dringend: Weniger als 1 Woche' }; if (daysLeft <= 7) return {color: '#dc3545', title: 'Dringend: Weniger als 1 Woche'};
if (daysLeft <= 21) return { color: '#ffc107', title: 'Mittel: Weniger als 3 Wochen' }; if (daysLeft <= 21) return {color: '#ffc107', title: 'Mittel: Weniger als 3 Wochen'};
return { color: '#28a745', title: 'Im Plan: Mehr als 3 Wochen' }; return {color: '#28a745', title: 'Im Plan: Mehr als 3 Wochen'};
} }
}, },
template: `<span :style="{ color: lightInfo.color, fontSize: '1.2em' }" class="mr-2" :title="lightInfo.title">&#9679;</span>` template: `<span :style="{ color: lightInfo.color, fontSize: '1.2em' }" class="mr-2" :title="lightInfo.title">&#9679;</span>`
}); });
Vue.component('assign-company-modal', { Vue.component('rml-documentation-viewer-admin', {
props: ['workorderId'], props: ['workorderId'],
template: ` template: `
<tt-modal :show="true" title="Firma zuweisen" @submit="submit" @update:show="$emit('close')"> <div class="p-3 bg-light">
<tt-select label="Firma" :options="companies" v-model="selectedCompanyId" sm row required /> <div v-if="loading" class="text-center p-5"><i class="fas fa-spinner fa-spin fa-2x"></i></div>
</tt-modal> <div v-else class="row">
<div class="col-lg-6">
<tt-file-gallery :files="docs" @selection-changed="selectedDocs = $event" selectable />
</div>
<div class="col-lg-6">
<div class="card mb-3">
<div class="card-header"><h5><i class="fas fa-exclamation-triangle text-danger mr-2"></i>Korrektur anfordern</h5></div>
<div class="card-body">
<p class="small text-muted">Wählen Sie die zu korrigierenden Dokumente aus der Galerie aus und geben Sie einen Grund an.</p>
<tt-textarea v-model="correctionText" label="Grund für die Korrektur" sm row />
<tt-button text="Korrektur anfordern" @click="requestCorrection" :loading="correctionLoading" additional-class="btn-danger float-right"/>
</div>
</div>
<!-- add a new card with a green button Dokumentation akzeptieren-->
<div class="card mb-3">
<div class="card-header"><h5><i class="fas fa-check-circle text-success mr-2"></i>Dokumentation akzeptieren</h5></div>
<div class="card-body">
<p class="small text-muted">Wenn die Dokumentation korrekt ist, können Sie sie hier akzeptieren.</p>
<tt-button text="Dokumentation akzeptieren"
@click="$emit('accept-documentation', workorderId)"
additional-class="btn-success float-right"
icon="fas fa-check"
/>
</div>
</div>
<div class="card mt-3">
<div class="card-header"><h5><i class="fas fa-history mr-2"></i>Journal</h5></div>
<div class="card-body p-0" style="max-height: 200px; overflow-y: auto;">
<ul v-if="journals.length" class="list-group list-group-flush">
<li v-for="log in journals" :key="log.id" class="list-group-item small">
<strong>{{ formatDate(log.create) }} ({{ log.createByName }}):</strong>
<div class="text-muted" style="white-space: pre-wrap;">{{ log.text }}</div>
</li>
</ul>
<div v-else class="card-body text-muted text-center">Keine Journaleinträge.</div>
</div>
<div class="card-footer">
<tt-textarea v-model="newJournalMessage" placeholder="Ihre Nachricht oder Anmerkung..." rows="2" />
<tt-button
text="Eintrag speichern"
@click="addJournalEntry"
:loading="addingJournalEntry"
additional-class="btn-info btn-sm w-100 mt-2"
icon="fas fa-paper-plane"
/>
</div>
</div>
</div>
</div>
</div>
`, `,
data() { return { companies: [], selectedCompanyId: null } }, data() {
async mounted() { return {
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getCompanies`); loading: true,
this.companies = response.data; correctionLoading: false,
docs: [],
journals: [],
selectedDocs: [],
correctionText: '',
newJournalMessage: '',
addingJournalEntry: false,
}
}, },
methods: { methods: {
async submit() { async fetchData() {
if (!this.selectedCompanyId) return window.notify('error', 'Bitte eine Firma auswählen.'); this.loading = true;
try { try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/assignWorkorder`, { const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getDocumentation`, { params: { workorderId: this.workorderId }});
this.docs = response.data.docs;
this.journals = response.data.journals;
} catch(e) {
window.notify('error', 'Dokumentation konnte nicht geladen werden.');
} finally {
this.loading = false;
}
},
async requestCorrection() {
if (!this.correctionText) return window.notify('error', 'Bitte geben Sie einen Grund für die Korrektur an.');
if (this.selectedDocs.length === 0) return window.notify('error', 'Bitte wählen Sie mindestens ein Dokument für die Korrektur aus.');
this.correctionLoading = true;
try {
const payload = {
workorderId: this.workorderId, workorderId: this.workorderId,
companyId: this.selectedCompanyId text: this.correctionText,
}); fileIds: this.selectedDocs
if(response.data.success) { };
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/requestCorrection`, payload);
if (response.data.success) {
window.notify('success', response.data.message); window.notify('success', response.data.message);
this.$emit('close'); this.correctionText = '';
this.selectedDocs = [];
await this.fetchData();
this.$emit('workorder-updated');
} else { } else {
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.'); window.notify('error', response.data.message);
} }
} catch (e) { } catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.'); window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} }
} this.correctionLoading = false;
} },
}); async addJournalEntry() {
if (!this.newJournalMessage.trim()) {
Vue.component('documentation-viewer-modal', { return window.notify('error', 'Bitte geben Sie eine Nachricht ein.');
props: ['workorderId'], }
template: ` this.addingJournalEntry = true;
<tt-modal :show="true" :title="'Dokumentation für Auftrag #' + workorderId" :save="false" :delete="false" @update:show="$emit('close')"> try {
<div class="card"> const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/addJournal`, {
<div class="card-header"> workorderId: this.workorderId,
<h5>Hochgeladene Dokumente</h5> text: this.newJournalMessage
</div> });
<div v-if="loading" class="card-body text-center"><i class="fas fa-spinner fa-spin fa-2x"></i></div> if (response.data.success) {
<div v-else-if="!docs.length" class="card-body text-center text-muted">Keine Dokumente vorhanden.</div> window.notify('success', response.data.message || 'Journal-Eintrag hinzugefügt.');
<ul v-else class="list-group list-group-flush"> this.newJournalMessage = '';
<li v-for="doc in docs" :key="doc.id" class="list-group-item"> this.journals = response.data.journals;
<a :href="'/File/download?id=' + doc.fileId" target="_blank"> } else {
<i class="fas fa-file-download mr-2"></i> {{ doc.fileName }} window.notify('error', response.data.message || 'Eintrag konnte nicht gespeichert werden.');
</a> }
<div class="text-muted small mt-1"> } catch (e) {
<strong>Typ:</strong> {{ getDocTypeText(doc.documentType) }} <br/> window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
<strong>Beschreibung:</strong> {{ doc.description || '-' }} <br/> } finally {
<strong>Hochgeladen von:</strong> {{ doc.userName }} am {{ formatDate(doc.create) }} this.addingJournalEntry = false;
</div> }
</li>
</ul>
</div>
</tt-modal>
`,
data() {
return { loading: false, docs: [] }
},
methods: {
async fetchDocs() {
this.loading = true;
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getDocumentation`, { params: { workorderId: this.workorderId }});
this.docs = response.data;
this.loading = false;
}, },
formatDate(timestamp) { formatDate(timestamp) {
return window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm'); return window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm');
}, },
getDocTypeText(type) {
const types = [
{ value: 'photo_before', text: 'Foto: Zustand vorher' },
{ value: 'photo_during', text: 'Foto: Während der Arbeit' },
{ value: 'photo_after', text: 'Foto: Zustand nachher' },
{ value: 'measurement_protocol', text: 'Messprotokoll (z.B. OTDR)' },
{ value: 'customer_signature', text: 'Unterschriebenes Arbeitsprotokoll' },
];
return types.find(t => t.value === type)?.text || type;
}
}, },
mounted() { mounted() {
this.fetchDocs(); this.fetchData();
} }
}); });

View File

@@ -0,0 +1,30 @@
/*
* CSS for Workorder Table Row Highlighting
*/
/* Urgent: Deadline passed or less than 1 week away */
.table-hover .tt-rml-workorder-urgent:hover,
.tt-rml-workorder-urgent {
background-color: #fbe9e7 !important; /* Soft Red */
}
/* Medium: Deadline less than 3 weeks away */
.table-hover .tt-rml-workorder-medium:hover,
.tt-rml-workorder-medium {
background-color: #fff8e1 !important; /* Soft Yellow */
}
/* On Track: Deadline more than 3 weeks away */
.table-hover .tt-rml-workorder-ontrack:hover,
.tt-rml-workorder-ontrack {
background-color: #e8f5e9 !important; /* Soft Green */
}
/* Irrelevant: No deadline or status makes it not applicable */
.table-hover .tt-rml-workorder-irrelevant:hover,
.tt-rml-workorder-irrelevant {
background-color: #fafafa !important; /* Very light grey */
}
.tt-file-gallery-item.border.border-danger {
border: 4px solid #f1556c!important;
}

View File

@@ -1,17 +1,9 @@
// RMLWorkorderCompany.js // RMLWorkorderCompany.js
Vue.component('r-m-l-workorder-company', { Vue.component('r-m-l-workorder-company', {
template: ` template: `
<tt-card> <tt-card>
<schedule-appointment-modal
v-if="scheduleModalWorkorderId"
:workorder-id="scheduleModalWorkorderId"
@close="scheduleModalWorkorderId = null; $refs.table.$refs.table.refreshTable()"
/>
<tt-table-crud <tt-table-crud
ref="table" ref="table"
@schedule="scheduleModalWorkorderId = $event.id"
:crud-config="crudConfig" :crud-config="crudConfig"
> >
<template v-slot:preorderinfo="{ row }"> <template v-slot:preorderinfo="{ row }">
@@ -29,7 +21,16 @@ Vue.component('r-m-l-workorder-company', {
</template> </template>
<template v-slot:appointmentdate="{ row }"> <template v-slot:appointmentdate="{ row }">
{{ formatDate(row.appointmentDate) }} <div v-if="!row.appointmentDate && ['assigned', 'correction_requested'].includes(row.status)">
<tt-date-picker
placeholder="Termin festlegen..."
:date-range="false"
@input="setAppointment(row, $event)"
sm
no-form-group
/>
</div>
<span v-else>{{ formatDate(row.appointmentDate) }}</span>
</template> </template>
<template v-slot:expandedRow="{ row }"> <template v-slot:expandedRow="{ row }">
@@ -44,18 +45,24 @@ Vue.component('r-m-l-workorder-company', {
`, `,
data() { data() {
return { return {
scheduleModalWorkorderId: null,
crudConfig: { crudConfig: {
...window.TT_CONFIG.CRUD_CONFIG, ...window.TT_CONFIG.CRUD_CONFIG,
expandable: true, expandable: true,
additionalActions: [ customRowClass: (row) => {
{ const deadlineDate = moment.unix(row.deadlineDate);
"key": "schedule",
"title": "Termin festlegen", if (['completed', 'new'].includes(row.status) || !deadlineDate.isValid()) {
"class": "fas fa-calendar-plus text-primary", return 'tt-rml-workorder-irrelevant';
"condition": (row) => row.status === 'assigned',
} }
]
const daysLeft = deadlineDate.diff(moment(), 'days');
if (daysLeft <= 7) return 'tt-rml-workorder-urgent';
if (daysLeft <= 21) return 'tt-rml-workorder-medium';
return 'tt-rml-workorder-ontrack';
},
additionalActions: []
} }
} }
}, },
@@ -67,6 +74,23 @@ Vue.component('r-m-l-workorder-company', {
formatDate(timestamp) { formatDate(timestamp) {
if (!timestamp) return ''; if (!timestamp) return '';
return window.moment.unix(timestamp).format('DD.MM.YYYY'); return window.moment.unix(timestamp).format('DD.MM.YYYY');
},
async setAppointment(workorder, date) {
if (!date) return;
try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/scheduleAppointment`, {
workorderId: workorder.id,
appointmentDate: date
});
if (response.data.success) {
window.notify('success', response.data.message);
this.$refs.table.$refs.table.refreshTable();
} else {
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.');
}
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
}
} }
} }
}); });
@@ -90,35 +114,6 @@ Vue.component('traffic-light', {
template: `<span :style="{ color: lightInfo.color, fontSize: '1.2em' }" class="mr-2" :title="lightInfo.title">&#9679;</span>` template: `<span :style="{ color: lightInfo.color, fontSize: '1.2em' }" class="mr-2" :title="lightInfo.title">&#9679;</span>`
}); });
Vue.component('schedule-appointment-modal', {
props: ['workorderId'],
template: `
<tt-modal :show="true" title="Termin festlegen" @submit="submit" @update:show="$emit('close')">
<tt-date-picker label="Termindatum" :date-range="false" v-model="appointmentDate" sm row required />
</tt-modal>
`,
data() { return { appointmentDate: null } },
methods: {
async submit() {
if (!this.appointmentDate) return window.notify('error', 'Bitte ein Datum auswählen.');
try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/scheduleAppointment`, {
workorderId: this.workorderId,
appointmentDate: this.appointmentDate
});
if(response.data.success) {
window.notify('success', response.data.message);
this.$emit('close');
} else {
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.');
}
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
}
}
}
});
Vue.component('documentation-manager', { Vue.component('documentation-manager', {
props: ['workorderId'], props: ['workorderId'],
template: ` template: `
@@ -126,29 +121,53 @@ Vue.component('documentation-manager', {
<div v-if="loadingWorkorder" class="text-center p-5"><i class="fas fa-spinner fa-spin fa-2x"></i></div> <div v-if="loadingWorkorder" class="text-center p-5"><i class="fas fa-spinner fa-spin fa-2x"></i></div>
<div v-else class="row"> <div v-else class="row">
<div class="col-lg-4 mb-3 mb-lg-0"> <div class="col-lg-4 mb-3 mb-lg-0">
<div class="card h-100"> <div>
<div class="card-body"> <div class="card h-100">
<h5 class="card-title">Benötigte Dokumente</h5> <div class="card-body">
<ul class="list-unstyled"> <h5 class="card-title">Benötigte Dokumente</h5>
<li v-for="docType in requiredDocTypes" :key="docType.value" class="mb-2 d-flex align-items-center"> <ul class="list-unstyled">
<i :class="isUploaded(docType.value) ? 'fas fa-check-circle text-success' : 'far fa-circle text-muted'" class="fa-fw mr-2"></i> <li v-for="docType in requiredDocTypes" :key="docType.value" class="mb-2 d-flex align-items-center">
<span>{{ docType.text }}</span> <i :class="isUploaded(docType.value) ? 'fas fa-check-circle text-success' : 'far fa-circle text-muted'" class="fa-fw mr-2"></i>
</li> <span>{{ docType.text }}</span>
</ul> </li>
<hr> </ul>
<tt-button <hr>
text="Auftrag abschließen" <tt-button
@click="completeWorkorder" text="Auftrag abschließen"
:disabled="!canComplete || workorder.status === 'completed'" @click="completeWorkorder"
:loading="completing" :disabled="!canComplete || workorder.status === 'completed'"
additional-class="btn-success w-100" :loading="completing"
icon="fas fa-check-double" additional-class="btn-success w-100"
/> icon="fas fa-check-double"
<small v-if="!canComplete" class="form-text text-muted text-center mt-2"> />
Bitte laden Sie alle benötigten Dokumente hoch, um den Auftrag abzuschließen. <small v-if="!canComplete" class="form-text text-muted text-center mt-2">
</small> Bitte laden Sie alle benötigten Dokumente hoch, um den Auftrag abzuschließen.
<div v-if="workorder.status === 'completed'" class="alert alert-secondary text-center mt-2 p-2"> </small>
Auftrag bereits abgeschlossen. <div v-if="workorder.status === 'completed'" class="alert alert-secondary text-center mt-2 p-2">
Auftrag bereits abgeschlossen.
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header"><h5><i class="fas fa-history mr-2"></i>Journal</h5></div>
<div class="card-body p-0" style="max-height: 200px; overflow-y: auto;">
<ul class="list-group list-group-flush">
<li v-if="journals.length === 0" class="list-group-item text-center text-muted">Keine Einträge vorhanden.</li>
<li v-for="log in journals" :key="log.id" class="list-group-item small" :class="{'list-group-item-danger': log.statusChange && log.statusChange.includes('correction_requested')}">
<strong>{{ formatDate(log.create) }} ({{ log.createByName }}):</strong>
<div class="text-muted" style="white-space: pre-wrap;">{{ log.text }}</div>
</li>
</ul>
</div>
<div class="card-footer" v-if="workorder.status !== 'completed'">
<tt-textarea v-model="newJournalMessage" placeholder="Ihre Nachricht oder Anmerkung..." rows="2" />
<tt-button
text="Eintrag speichern"
@click="addJournalEntry"
:loading="addingJournalEntry"
additional-class="btn-info btn-sm w-100 mt-2"
icon="fas fa-paper-plane"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -162,15 +181,30 @@ Vue.component('documentation-manager', {
<tt-input label="Beschreibung" v-model="uploadData.description" sm row placeholder="Optional"/> <tt-input label="Beschreibung" v-model="uploadData.description" sm row placeholder="Optional"/>
<div class="form-group row"> <div class="form-group row">
<label class="col-form-label col-sm-4 col-form-label-sm">Dateien</label> <label class="col-form-label col-sm-4 col-form-label-sm">Dateien</label>
<div class="col-sm-8"> <div class="col-sm-8 p-0">
<input type="file" class="form-control-file form-control-sm" @change="handleFileUpload" ref="fileInput" multiple /> <input type="file" class="form-control-file form-control-sm p-0" @change="handleFileUpload" ref="fileInput" multiple accept="image/*,.pdf,.doc,.docx" />
</div> </div>
</div> </div>
<tt-button text="Hochladen" @click="uploadFiles" :loading="uploading" additional-class="btn-primary float-right" icon="fas fa-upload" /> <tt-button text="Hochladen" @click="uploadFiles" :loading="uploading" additional-class="btn-primary float-right" icon="fas fa-upload" />
</div> </div>
</div> </div>
<tt-file-gallery :files="uploadedFiles" /> <tt-file-gallery
:files="filesWithStatus"
:edit-mode="workorder.status !== 'completed'"
:delete-mode="workorder.status !== 'completed'"
@delete-file="deleteDocumentation"
@update-file="updateDocumentation"
>
<template v-slot:file-edit="{ file }">
<tt-select
label="Dokumententyp"
:options="requiredDocTypes"
v-model="file.documentType"
sm
/>
</template>
</tt-file-gallery>
</div> </div>
</div> </div>
</div> </div>
@@ -182,6 +216,9 @@ Vue.component('documentation-manager', {
uploading: false, uploading: false,
completing: false, completing: false,
uploadedFiles: [], uploadedFiles: [],
journals: [],
newJournalMessage: '',
addingJournalEntry: false,
uploadData: { uploadData: {
files: [], files: [],
documentType: 'photo_before', documentType: 'photo_before',
@@ -199,9 +236,40 @@ Vue.component('documentation-manager', {
computed: { computed: {
canComplete() { canComplete() {
return this.requiredDocTypes.every(docType => this.isUploaded(docType.value)); return this.requiredDocTypes.every(docType => this.isUploaded(docType.value));
},
filesWithStatus() {
if (!this.journals || this.journals.length === 0) {
return this.uploadedFiles;
}
const correctionJournal = [...this.journals]
.sort((a, b) => b.create - a.create)
.find(j => j.statusChange && j.statusChange.includes('correction_requested'));
if (!correctionJournal || !correctionJournal.fileIds) {
return this.uploadedFiles;
}
try {
const incorrectFileIds = JSON.parse(correctionJournal.fileIds);
if (!Array.isArray(incorrectFileIds)) return this.uploadedFiles;
return this.uploadedFiles.map(file => {
if (incorrectFileIds.includes(file.id)) {
return { ...file, class: 'border border-danger' };
}
return file;
});
} catch (e) {
return this.uploadedFiles;
}
} }
}, },
methods: { methods: {
formatDate(timestamp) {
if (!timestamp) return '';
return window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm');
},
async loadWorkorder() { async loadWorkorder() {
this.loadingWorkorder = true; this.loadingWorkorder = true;
try { try {
@@ -218,7 +286,8 @@ Vue.component('documentation-manager', {
async fetchDocs() { async fetchDocs() {
try { try {
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/getDocumentation`, { params: { workorderId: this.workorderId }}); const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/getDocumentation`, { params: { workorderId: this.workorderId }});
this.uploadedFiles = response.data; this.uploadedFiles = response.data.docs;
this.journals = response.data.journals;
} catch(e) { } catch(e) {
window.notify('error', 'Dokumente konnten nicht geladen werden.'); window.notify('error', 'Dokumente konnten nicht geladen werden.');
} }
@@ -245,8 +314,9 @@ Vue.component('documentation-manager', {
this.$refs.fileInput.value = ''; this.$refs.fileInput.value = '';
this.uploadData.files = []; this.uploadData.files = [];
this.uploadData.description = ''; this.uploadData.description = '';
await this.fetchDocs();
await this.loadWorkorder(); // Reload to get updated status this.uploadedFiles = response.data.docs;
this.workorder = response.data.workorder;
} else { } else {
window.notify('error', response.data.error || 'Upload fehlgeschlagen.'); window.notify('error', response.data.error || 'Upload fehlgeschlagen.');
} }
@@ -271,9 +341,55 @@ Vue.component('documentation-manager', {
} }
this.completing = false; this.completing = false;
}, },
getDocTypeText(type) { async deleteDocumentation(file) {
const found = this.requiredDocTypes.find(t => t.value === type); try {
return found ? found.text : type; const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/deleteDocumentation`, { id: file.id });
if (response.data.success) {
window.notify('success', response.data.message);
this.uploadedFiles = response.data.docs;
} else {
window.notify('error', response.data.message || 'Löschen fehlgeschlagen.');
}
} catch (e) {
window.notify('error', 'Netzwerkfehler beim Löschen.');
}
},
async updateDocumentation(file) {
try {
const payload = { id: file.id, documentType: file.documentType };
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/updateDocumentation`, payload);
if (response.data.success) {
window.notify('success', response.data.message);
this.uploadedFiles = response.data.docs;
} else {
window.notify('error', response.data.message || 'Update fehlgeschlagen.');
}
} catch (e) {
window.notify('error', 'Netzwerkfehler beim Aktualisieren.');
}
},
async addJournalEntry() {
if (!this.newJournalMessage.trim()) {
return window.notify('error', 'Bitte geben Sie eine Nachricht ein.');
}
this.addingJournalEntry = true;
try {
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/addJournal`, {
workorderId: this.workorderId,
text: this.newJournalMessage
});
if (response.data.success) {
window.notify('success', response.data.message || 'Journal-Eintrag hinzugefügt.');
this.newJournalMessage = '';
this.journals = response.data.journals;
} else {
window.notify('error', response.data.message || 'Eintrag konnte nicht gespeichert werden.');
}
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.addingJournalEntry = false;
}
} }
}, },
async mounted() { async mounted() {

View File

@@ -1,3 +1,4 @@
/* tt-file-gallery.css */
.tt-file-gallery-grid { .tt-file-gallery-grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
@@ -13,11 +14,18 @@
cursor: pointer; cursor: pointer;
} }
.tt-file-gallery-thumbnail { .tt-file-gallery-thumbnail-wrapper {
position: relative;
width: 100%; width: 100%;
height: 100px; height: 100px;
object-fit: cover;
border-radius: 0.25rem; border-radius: 0.25rem;
overflow: hidden; /* Hide the scaled part of the image */
}
.tt-file-gallery-thumbnail {
width: 100%;
height: 100%;
object-fit: cover;
border: 1px solid #dee2e6; border: 1px solid #dee2e6;
transition: transform 0.2s; transition: transform 0.2s;
} }
@@ -30,8 +38,8 @@
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
right: 0; width: 100%;
bottom: 40px; /* Adjust to not cover filename */ height: 100%;
background: rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.4);
color: white; color: white;
display: flex; display: flex;
@@ -43,13 +51,13 @@
border-radius: 0.25rem; border-radius: 0.25rem;
} }
.tt-file-gallery-item:hover .tt-file-gallery-overlay { .tt-file-gallery-item:hover .tt-file-gallery-thumbnail-wrapper .tt-file-gallery-overlay {
opacity: 1; opacity: 1;
} }
.tt-file-gallery-icon-container { .tt-file-gallery-icon-container {
width: 100%; width: 100%;
height: 100px; height: 100%;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@@ -58,18 +66,40 @@
background-color: #f8f9fa; background-color: #f8f9fa;
text-decoration: none; text-decoration: none;
color: inherit; color: inherit;
transition: transform 0.2s;
} }
.tt-file-gallery-item:hover .tt-file-gallery-icon-container {
transform: scale(1.05);
}
.tt-file-gallery-filename { .tt-file-gallery-filename {
font-size: 0.8rem; font-size: 0.8rem;
margin-top: 0.5rem; margin-top: 0.5rem;
width: 100%; width: 100%;
padding: 0 4px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 0 0.25rem;
line-height: 1.2;
}
.tt-file-gallery-filename > span {
flex: 1 1 auto;
min-width: 0;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
padding: 0 4px;
} }
.tt-file-gallery-filename > i {
flex-shrink: 0;
}
/* --- Fullscreen Viewer Styles --- */ /* --- Fullscreen Viewer Styles --- */
.tt-fullscreen-overlay { .tt-fullscreen-overlay {

View File

@@ -0,0 +1,198 @@
/* --- tt-select.css --- */
.tt-select-modern {
position: relative;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.tt-select-modern .form-group {
margin-bottom: 0;
}
.tt-select-modern .tt-select-trigger {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 0.5rem 0.75rem;
font-size: 1rem;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
cursor: pointer;
text-align: left;
}
.tt-select-modern .tt-select-trigger.sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
border-radius: 0.2rem;
}
.tt-select-modern .tt-select-trigger:hover {
border-color: #80bdff;
}
.tt-select-modern .tt-select-trigger.open {
border-color: #80bdff;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}
.tt-select-modern .trigger-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
flex-grow: 1;
}
.tt-select-modern .trigger-text.placeholder {
color: #6c757d;
}
.tt-select-modern .trigger-arrow {
margin-left: 8px;
transition: transform 0.2s ease;
}
.tt-select-modern .tt-select-trigger.open .trigger-arrow {
transform: rotate(180deg);
}
.tt-select-modern .tt-select-dropdown {
position: absolute;
top: calc(100% + 4px);
left: 0;
min-width: 100%;
width: max-content;
z-index: 1050;
background-color: #fff;
border-radius: 0.3rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
opacity: 0;
transform: translateY(-10px);
visibility: hidden;
transition: opacity 0.15s ease, transform 0.15s ease;
}
.tt-select-modern .tt-select-dropdown.show {
opacity: 1;
transform: translateY(0);
visibility: visible;
}
.tt-select-modern .dropdown-header {
display: none; /* Hidden on desktop */
}
.tt-select-modern .search-input-wrapper {
padding: 0.5rem;
border-bottom: 1px solid #e9ecef;
}
.tt-select-modern .search-input {
width: 100%;
padding: 0.375rem 0.75rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
}
.tt-select-modern .options-list {
list-style: none;
padding: 0.5rem 0;
margin: 0;
max-height: 250px;
overflow-y: auto;
}
.tt-select-modern .option-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.5rem 1rem;
cursor: pointer;
transition: background-color 0.15s ease;
user-select: none;
white-space: nowrap;
}
.tt-select-modern .option-label {
display: flex;
align-items: center;
}
.tt-select-modern .option-item input {
display: none;
}
.tt-select-modern .option-item:hover {
background-color: #f8f9fa;
}
.tt-select-modern .option-item.selected {
background-color: #e2f0ff;
font-weight: 600;
color: #0056b3;
}
.tt-select-modern .option-checkmark {
color: #0056b3;
}
.tt-select-modern .no-results {
padding: 0.5rem 1rem;
color: #6c757d;
text-align: center;
}
/* Mobile Compliance */
@media (max-width: 768px) {
.tt-select-modern .tt-select-trigger,
.tt-select-modern .option-item {
font-size: 1.1rem; /* Bigger font for readability */
}
.tt-select-modern .tt-select-dropdown.show {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
border-radius: 0;
display: flex;
flex-direction: column;
background-color: #f8f9fa;
transform: none;
}
.tt-select-modern .dropdown-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
background-color: #fff;
border-bottom: 1px solid #dee2e6;
font-size: 1.2rem;
font-weight: 600;
}
.tt-select-modern .close-btn {
font-size: 1.5rem;
cursor: pointer;
line-height: 1;
border: none;
background: none;
}
.tt-select-modern .options-list {
max-height: none;
flex-grow: 1;
}
}

View File

@@ -1,13 +1,17 @@
// tt-file-gallery.js
Vue.component('tt-file-gallery', { Vue.component('tt-file-gallery', {
props: { props: {
files: { type: Array, default: () => [] } files: { type: Array, default: () => [] },
editMode: { type: Boolean, default: false },
deleteMode: { type: Boolean, default: false },
selectable: { type: Boolean, default: false },
}, },
data() { data() {
return { return {
fullscreenItem: null, // Holds the file being viewed fullscreenItem: null,
currentImageIndex: 0, currentImageIndex: 0,
editingFile: null,
// Zoom & Pan state selectedFiles: [],
zoom: 1, zoom: 1,
pan: { x: 0, y: 0 }, pan: { x: 0, y: 0 },
isPanning: false, isPanning: false,
@@ -23,7 +27,6 @@ Vue.component('tt-file-gallery', {
return this.fullscreenItem && this.isImage(this.fullscreenItem); return this.fullscreenItem && this.isImage(this.fullscreenItem);
}, },
imageTransformStyle() { imageTransformStyle() {
// Apply CSS transform for zoom and pan
const { x, y } = this.pan; const { x, y } = this.pan;
return { return {
transform: `translate(${x}px, ${y}px) scale(${this.zoom})`, transform: `translate(${x}px, ${y}px) scale(${this.zoom})`,
@@ -33,34 +36,33 @@ Vue.component('tt-file-gallery', {
}, },
fullscreenDownloadUrl() { fullscreenDownloadUrl() {
if (!this.fullscreenItem) return '#'; if (!this.fullscreenItem) return '#';
return `/File/download?id=${this.fullscreenItem.id}`; return `/File/download?id=${this.fullscreenItem.fileId}`;
} }
}, },
methods: { methods: {
// File type checks isImage: file => file.mimetype && file.mimetype.startsWith('image/'),
isImage(file) { isPdf: file => file.mimetype === 'application/pdf',
return file.mimetype && file.mimetype.startsWith('image/');
},
isPdf(file) {
return file.mimetype === 'application/pdf';
},
// Get icon for non-image/pdf files
getFileIcon(file) { getFileIcon(file) {
const extension = file.fileName?.split('.').pop().toLowerCase(); const extension = file.fileName?.split('.').pop().toLowerCase();
switch (extension) { switch (extension) {
case 'doc': case 'doc': case 'docx': return 'fas fa-file-word text-primary';
case 'docx': return 'fas fa-file-word text-primary'; case 'xls': case 'xlsx': return 'fas fa-file-excel text-success';
case 'xls': case 'zip': case 'rar': return 'fas fa-file-archive text-warning';
case 'xlsx': return 'fas fa-file-excel text-success';
case 'zip':
case 'rar': return 'fas fa-file-archive text-warning';
default: return 'fas fa-file text-secondary'; default: return 'fas fa-file text-secondary';
} }
}, },
toggleSelection(fileId) {
// Viewer controls if (!this.selectable) return;
const index = this.selectedFiles.indexOf(fileId);
if (index > -1) {
this.selectedFiles.splice(index, 1);
} else {
this.selectedFiles.push(fileId);
}
this.$emit('selection-changed', this.selectedFiles);
},
openViewer(file) { openViewer(file) {
if(this.editingFile) return;
this.fullscreenItem = file; this.fullscreenItem = file;
if (this.isImage(file)) { if (this.isImage(file)) {
this.currentImageIndex = this.imageFiles.findIndex(img => img.id === file.id); this.currentImageIndex = this.imageFiles.findIndex(img => img.id === file.id);
@@ -68,9 +70,7 @@ Vue.component('tt-file-gallery', {
this.resetZoomAndPan(); this.resetZoomAndPan();
this.$nextTick(() => { this.$refs.viewer?.focus(); }); this.$nextTick(() => { this.$refs.viewer?.focus(); });
}, },
closeViewer() { closeViewer() { this.fullscreenItem = null; },
this.fullscreenItem = null;
},
navigateImage(direction) { navigateImage(direction) {
const newIndex = this.currentImageIndex + direction; const newIndex = this.currentImageIndex + direction;
if (newIndex >= 0 && newIndex < this.imageFiles.length) { if (newIndex >= 0 && newIndex < this.imageFiles.length) {
@@ -79,9 +79,8 @@ Vue.component('tt-file-gallery', {
this.resetZoomAndPan(); this.resetZoomAndPan();
} }
}, },
// Event handlers for keyboard and clicks
handleKeyDown(event) { handleKeyDown(event) {
event.stopPropagation();
if (!this.fullscreenItem) return; if (!this.fullscreenItem) return;
switch (event.key) { switch (event.key) {
case 'Escape': this.closeViewer(); break; case 'Escape': this.closeViewer(); break;
@@ -89,24 +88,16 @@ Vue.component('tt-file-gallery', {
case 'ArrowRight': this.isViewingImage && this.navigateImage(1); break; case 'ArrowRight': this.isViewingImage && this.navigateImage(1); break;
} }
}, },
// --- Zoom and Pan Methods ---
resetZoomAndPan() { resetZoomAndPan() {
this.zoom = 1; this.zoom = 1; this.pan = { x: 0, y: 0 }; this.isPanning = false;
this.pan = { x: 0, y: 0 };
this.isPanning = false;
}, },
// Mouse Wheel Zoom
handleWheel(e) { handleWheel(e) {
if (!this.isViewingImage) return; if (!this.isViewingImage) return;
e.preventDefault(); e.preventDefault();
const scaleFactor = 0.2; const scaleFactor = 0.2;
const newZoom = this.zoom - (e.deltaY > 0 ? scaleFactor : -scaleFactor); const newZoom = this.zoom - (e.deltaY > 0 ? scaleFactor : -scaleFactor);
this.zoom = Math.max(1, Math.min(newZoom, 5)); // Clamp zoom between 1x and 5x this.zoom = Math.max(1, Math.min(newZoom, 5));
}, },
// Mouse Drag to Pan
onPanStart(e) { onPanStart(e) {
if (this.zoom <= 1) return; if (this.zoom <= 1) return;
e.preventDefault(); e.preventDefault();
@@ -119,79 +110,81 @@ Vue.component('tt-file-gallery', {
this.pan.x = e.clientX - this.panStart.x; this.pan.x = e.clientX - this.panStart.x;
this.pan.y = e.clientY - this.panStart.y; this.pan.y = e.clientY - this.panStart.y;
}, },
onPanEnd() { onPanEnd() { this.isPanning = false; },
this.isPanning = false; onTouchStart(e) { /* ... touch logic ... */ },
}, onTouchMove(e) { /* ... touch logic ... */ },
onTouchEnd(e) { /* ... touch logic ... */ },
// Touch Events for Mobile (Pinch-to-Zoom & Pan) startEdit(file, event) {
onTouchStart(e) { event?.stopPropagation();
if (this.zoom <= 1 && e.touches.length === 1) return; this.editingFile = { ...file }; // create a copy for editing
e.preventDefault(); },
if (e.touches.length === 1) { // Pan cancelEdit(event) {
this.isPanning = true; console.log('Edit cancelled');
this.panStart.x = e.touches[0].clientX - this.pan.x; event?.stopPropagation();
this.panStart.y = e.touches[0].clientY - this.pan.y; this.editingFile = null;
} else if (e.touches.length === 2) { // Zoom },
this.lastPinchDist = Math.hypot( saveEdit(event) {
e.touches[0].clientX - e.touches[1].clientX, event?.stopPropagation();
e.touches[0].clientY - e.touches[1].clientY this.$emit('update-file', this.editingFile);
); this.editingFile = null;
},
deleteFile(file, event) {
event?.stopPropagation();
if (confirm(`Sind Sie sicher, dass Sie die Datei "${file.fileName}" löschen möchten?`)) {
this.$emit('delete-file', file);
} }
}, },
onTouchMove(e) {
if (!this.isPanning && e.touches.length !== 2) return;
e.preventDefault();
if (e.touches.length === 1 && this.isPanning) { // Pan
this.pan.x = e.touches[0].clientX - this.panStart.x;
this.pan.y = e.touches[0].clientY - this.panStart.y;
} else if (e.touches.length === 2) { // Zoom
const pinchDist = Math.hypot(
e.touches[0].clientX - e.touches[1].clientX,
e.touches[0].clientY - e.touches[1].clientY
);
const scaleFactor = 0.01;
const newZoom = this.zoom + (pinchDist - this.lastPinchDist) * scaleFactor;
this.zoom = Math.max(1, Math.min(newZoom, 5)); // Clamp zoom
this.lastPinchDist = pinchDist;
}
},
onTouchEnd(e) {
this.isPanning = false;
if (e.touches.length < 2) {
this.lastPinchDist = 0;
}
}
}, },
watch: { watch: {
fullscreenItem(newItem) { fullscreenItem(newItem) {
// Prevent body scroll when viewer is open
document.body.style.overflow = newItem ? 'hidden' : ''; document.body.style.overflow = newItem ? 'hidden' : '';
} }
}, },
template: ` template: `
<div class="card"> <div class="card">
<div class="card-header"><h5>Hochgeladene Dokumente</h5></div> <div class="card-header"><i class="fas fa-images mr-2"></i><h5>Hochgeladene Dokumente</h5></div>
<div v-if="!files.length" class="card-body text-center text-muted">Keine Dokumente vorhanden.</div> <div v-if="!files.length" class="card-body text-center text-muted">Keine Dokumente vorhanden.</div>
<div v-else class="card-body"> <div v-else class="card-body">
<div class="tt-file-gallery-grid"> <div class="tt-file-gallery-grid">
<div v-for="file in files" :key="file.id" class="tt-file-gallery-item" @click="openViewer(file)"> <div v-for="file in files" :key="file.id"
<template v-if="isImage(file)"> class="tt-file-gallery-item"
<img :src="'/File/show?id=' + file.id + '&size=small'" class="tt-file-gallery-thumbnail" :alt="file.fileName"> :class="[{ 'selected': selectable && selectedFiles.includes(file.id) }, file.class]"
<div class="tt-file-gallery-overlay"><i class="fas fa-search-plus"></i></div> @click="openViewer(file)">
</template>
<template v-else-if="isPdf(file)"> <div v-if="selectable" class="selection-indicator" @click.stop="toggleSelection(file.id)">
<div class="tt-file-gallery-icon-container"><i class="fas fa-file-pdf fa-3x text-danger"></i></div> <i :class="selectedFiles.includes(file.id) ? 'fas fa-check-circle text-primary' : 'far fa-circle text-muted'"></i>
</template> </div>
<template v-else>
<a :href="'/File/download?id=' + file.id" target="_blank" @click.stop class="tt-file-gallery-icon-container"> <div class="tt-file-gallery-thumbnail-wrapper">
<i :class="getFileIcon(file)" class="fa-3x"></i> <template v-if="isImage(file)">
</a> <img :src="'/File/show?id=' + file.fileId + '&size=small'" class="tt-file-gallery-thumbnail" :alt="file.fileName">
</template> </template>
<div class="tt-file-gallery-filename" :title="file.fileName">{{ file.fileName }}</div> <template v-else-if="isPdf(file)">
<div class="tt-file-gallery-icon-container"><i class="fas fa-file-pdf fa-3x text-danger"></i></div>
</template>
<template v-else>
<a :href="'/File/download?id=' + file.fileId" target="_blank" @click.stop class="tt-file-gallery-icon-container">
<i :class="getFileIcon(file)" class="fa-3x"></i>
</a>
</template>
<div class="tt-file-gallery-overlay" @click.stop="openViewer(file)"><i class="fas fa-search-plus"></i></div>
</div>
<div class="tt-file-gallery-filename" :title="file.fileName">
<span>{{ file.fileName }}</span>
<i v-if="editMode && !editingFile" class="fas fa-edit text-primary ml-1 action-icon" @click="startEdit(file, $event)"></i>
<i v-if="deleteMode && !editingFile" class="fas fa-trash text-danger ml-1 action-icon" @click="deleteFile(file, $event)"></i>
</div>
</div> </div>
</div> </div>
</div> </div>
<tt-modal v-if="editingFile" :show="true" title="Dokument bearbeiten" @close="cancelEdit" @submit="saveEdit" :delete="false">
<slot name="file-edit" :file="editingFile"></slot>
</tt-modal>
<div v-if="fullscreenItem" class="tt-fullscreen-overlay" @click.self="closeViewer" @keydown="handleKeyDown" tabindex="-1" ref="viewer"> <div v-if="fullscreenItem" class="tt-fullscreen-overlay" @click.self="closeViewer" @keydown="handleKeyDown" tabindex="-1" ref="viewer">
<div class="tt-fullscreen-toolbar"> <div class="tt-fullscreen-toolbar">
<a v-if="isViewingImage" :href="fullscreenDownloadUrl" download class="tt-fullscreen-btn" title="Download"> <a v-if="isViewingImage" :href="fullscreenDownloadUrl" download class="tt-fullscreen-btn" title="Download">
@@ -199,33 +192,19 @@ Vue.component('tt-file-gallery', {
</a> </a>
<button class="tt-fullscreen-btn" @click="closeViewer" title="Close"><i class="fas fa-times"></i></button> <button class="tt-fullscreen-btn" @click="closeViewer" title="Close"><i class="fas fa-times"></i></button>
</div> </div>
<div class="tt-fullscreen-content" @click.self="closeViewer"> <div class="tt-fullscreen-content" @click.self="closeViewer">
<template v-if="isViewingImage"> <template v-if="isViewingImage">
<div class="tt-fullscreen-image-wrapper" <div class="tt-fullscreen-image-wrapper" @wheel="handleWheel" @mousedown="onPanStart" @mousemove="onPanMove" @mouseup="onPanEnd" @mouseleave="onPanEnd">
@wheel="handleWheel" <img :src="'/File/show?id=' + fullscreenItem.fileId" class="tt-fullscreen-image" :style="imageTransformStyle" @click.stop />
@mousedown="onPanStart"
@mousemove="onPanMove"
@mouseup="onPanEnd"
@mouseleave="onPanEnd"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd">
<img :src="'/File/show?id=' + fullscreenItem.id" class="tt-fullscreen-image" :style="imageTransformStyle" @click.stop />
</div> </div>
</template> </template>
<template v-else-if="isPdf(fullscreenItem)"> <template v-else-if="isPdf(fullscreenItem)">
<iframe :src="'/File/show?id=' + fullscreenItem.id" class="tt-fullscreen-pdf" @click.stop></iframe> <iframe :src="'/File/show?id=' + fullscreenItem.fileId" class="tt-fullscreen-pdf" @click.stop></iframe>
</template> </template>
</div> </div>
<template v-if="isViewingImage"> <template v-if="isViewingImage">
<button class="tt-fullscreen-nav-btn left" @click.stop="navigateImage(-1)" v-if="currentImageIndex > 0"> <button class="tt-fullscreen-nav-btn left" @click.stop="navigateImage(-1)" v-if="currentImageIndex > 0"><i class="fas fa-chevron-left"></i></button>
<i class="fas fa-chevron-left"></i> <button class="tt-fullscreen-nav-btn right" @click.stop="navigateImage(1)" v-if="currentImageIndex < imageFiles.length - 1"><i class="fas fa-chevron-right"></i></button>
</button>
<button class="tt-fullscreen-nav-btn right" @click.stop="navigateImage(1)" v-if="currentImageIndex < imageFiles.length - 1">
<i class="fas fa-chevron-right"></i>
</button>
</template> </template>
</div> </div>
</div> </div>

View File

@@ -12,7 +12,6 @@ Vue.component('tt-modal', {
if (!newVal) { if (!newVal) {
this.$emit('close') this.$emit('close')
} }
// if show now is true then focus the first input element
if (newVal) { if (newVal) {
this.$nextTick(() => { this.$nextTick(() => {
const input = this.$refs.modal.querySelector('input') const input = this.$refs.modal.querySelector('input')

View File

@@ -1,50 +1,42 @@
Vue.component('tt-select', { Vue.component('tt-select', {
props: { props: {
options: { type: Array, required: true }, options: {type: Array, required: true},
label: { type: String, default: null }, label: {type: String, default: null},
required: { type: Boolean, default: false }, required: {type: Boolean, default: false},
value: { type: [String, Number, Array], default: null }, value: {type: [String, Number, Array], default: null},
disabled: { type: Boolean, default: false }, disabled: {type: Boolean, default: false},
suffix: { type: String, default: null }, suffix: {type: String, default: null},
sm: { type: Boolean, default: false }, sm: {type: Boolean, default: false},
row: { type: Boolean, default: false }, row: {type: Boolean, default: false},
multiple: { type: Boolean, default: false }, multiple: {type: Boolean, default: false},
searchable: { type: Boolean, default: true } searchable: {type: Boolean, default: true}
}, },
data() { data() {
return { return {
open: false, open: false,
searchQuery: '', searchQuery: '',
// internal model: array if multiple, else primitive selected: this.multiple ? (Array.isArray(this.value) ? [...this.value] : []) : this.value
selected: this.multiple
? (Array.isArray(this.value) ? [...this.value] : [])
: this.value
}; };
}, },
watch: { watch: {
// keep internal model in sync with external v-model
value(newVal) { value(newVal) {
this.selected = this.multiple this.selected = this.multiple ? (Array.isArray(newVal) ? [...newVal] : []) : newVal;
? (Array.isArray(newVal) ? [...newVal] : [])
: newVal;
}, },
// Enhancement: Handle focus and scroll on open
open(isOpen) { open(isOpen) {
if (isOpen) { if (!isOpen) {
this.$nextTick(() => { this.searchQuery = ''; // Reset search on close
if (this.$refs.dropdownMenu) { return;
// 2. Scroll to the top when opened
this.$refs.dropdownMenu.scrollTop = 0;
}
if (this.searchable && this.$refs.searchInput) {
// 1. Focus the input when opened
this.$refs.searchInput.focus();
}
});
} }
this.$nextTick(() => {
if (this.searchable && this.$refs.searchInput) {
this.$refs.searchInput.focus();
}
if (this.$refs.optionsList) {
this.$refs.optionsList.scrollTop = 0;
}
});
} }
}, },
@@ -57,55 +49,42 @@ Vue.component('tt-select', {
}, },
computed: { computed: {
// normalize all options to { value, text, disabled }
normalizedOptions() { normalizedOptions() {
return this.options.map(opt => { return this.options.map(opt =>
if (opt !== null && typeof opt === 'object') { (opt !== null && typeof opt === 'object')
return { ? {value: opt.value, text: opt.text, disabled: !!opt.disabled}
value: opt.value, : {value: opt, text: String(opt), disabled: false}
text: opt.text,
disabled: !!opt.disabled
};
}
return {
value: opt,
text: String(opt),
disabled: false
};
});
},
// filter by searchQuery
filteredOptions() {
if (!this.searchable || !this.searchQuery) {
return this.normalizedOptions;
}
const q = this.searchQuery.toLowerCase();
return this.normalizedOptions.filter(o =>
o.text.toLowerCase().includes(q)
); );
}, },
// what to show on the button filteredOptions() {
if (!this.searchable || !this.searchQuery) return this.normalizedOptions;
const q = this.searchQuery.toLowerCase();
return this.normalizedOptions.filter(o => o.text.toLowerCase().includes(q));
},
displayText() { displayText() {
if (this.multiple) { const addSuffix = text => text ? `${text}${this.suffix ? ` ${this.suffix}` : ''}` : '';
const arr = Array.isArray(this.selected) ? this.selected : [];
const count = arr.length; if (!this.multiple) {
if (count === 0) return ''; const opt = this.normalizedOptions.find(o => o.value === this.selected);
if (count === 1) { return opt ? addSuffix(opt.text) : 'Auswählen...';
const o = this.normalizedOptions.find(x => x.value === arr[0]);
return o
? o.text + (this.suffix ? ' ' + this.suffix : '')
: '';
}
// more than one selected
return `${count} ausgewählt`;
} }
// single select
const sel = this.normalizedOptions.find(o => o.value === this.selected); const count = Array.isArray(this.selected) ? this.selected.length : 0;
return sel if (count === 0) return 'Auswählen...';
? sel.text + (this.suffix ? ' ' + this.suffix : '') if (count === 1) {
: ''; const opt = this.normalizedOptions.find(o => o.value === this.selected[0]);
return opt ? addSuffix(opt.text) : '';
}
return `${count} ausgewählt`;
},
hasSelection() {
if (this.multiple) {
return Array.isArray(this.selected) && this.selected.length > 0;
}
return this.selected !== null && this.selected !== undefined && this.selected !== '';
} }
}, },
@@ -116,7 +95,7 @@ Vue.component('tt-select', {
}, },
onClickOutside(e) { onClickOutside(e) {
if (!this.$el.contains(e.target)) { if (this.$el && !this.$el.contains(e.target)) {
this.open = false; this.open = false;
} }
}, },
@@ -129,111 +108,80 @@ Vue.component('tt-select', {
selectOption(opt) { selectOption(opt) {
if (opt.disabled) return; if (opt.disabled) return;
if (this.multiple) {
const arr = Array.isArray(this.selected) ? [...this.selected] : [];
const idx = arr.indexOf(opt.value);
if (idx > -1) arr.splice(idx, 1);
else arr.push(opt.value);
this.selected = arr; if (this.multiple) {
this.$emit('input', arr); const newSelection = Array.isArray(this.selected) ? [...this.selected] : [];
const index = newSelection.indexOf(opt.value);
if (index > -1) {
newSelection.splice(index, 1);
} else {
newSelection.push(opt.value);
}
this.selected = newSelection;
} else { } else {
this.selected = opt.value; this.selected = opt.value;
this.$emit('input', opt.value); this.open = false; // Close on selection for single mode
this.open = false;
} }
this.$emit('input', this.selected);
}, },
// Enhancement: Handle Enter key press on search input
handleEnter() { handleEnter() {
// 4. If search is active and only one result is left, select it
if (this.searchQuery && this.filteredOptions.length === 1) { if (this.searchQuery && this.filteredOptions.length === 1) {
this.selectOption(this.filteredOptions[0]); this.selectOption(this.filteredOptions[0]);
// Ensure dropdown closes for both single and multi-select mode if (!this.multiple) this.open = false;
this.open = false;
} }
} }
}, },
template: ` template: `
<div class="form-group" :class="{ row: row }"> <div class="form-group" :class="[{ 'row': row }, 'tt-select-modern']">
<label v-if="label" <label v-if="label" :for="'tt-select-' + _uid"
:for="label" :class="['col-form-label', { 'col-sm-4': row, 'col-form-label-sm': sm && row }]">
:class="{
'col-form-label': row,
'col-sm-4': row,
'col-form-label-sm': sm && row
}">
{{ label }} {{ label }}
</label> </label>
<div :class="row ? 'col-sm-8 p-0' : ''"> <div :class="{ 'col-sm-8 p-0': row }">
<div class="dropdown" :class="{ show: open }"> <div class="tt-select-container">
<button type="button" <button type="button" class="tt-select-trigger"
class="btn btn-outline-secondary form-control" :id="'tt-select-' + _uid"
:class="{ 'form-control-sm': sm, 'btn-sm': sm }" :class="{ 'sm': sm, 'open': open }"
:disabled="disabled" :disabled="disabled"
@click.stop="toggleDropdown" @click.stop="toggleDropdown">
style="display:flex; align-items:center;"> <span class="trigger-text" :class="{'placeholder': !hasSelection}">{{ displayText }}</span>
<span style=" <i class="fas fa-chevron-down trigger-arrow"></i>
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
flex: 1;
text-align: left;
">
{{ displayText || 'Auswählen...' }}
</span>
<i class="fas fa-chevron-down ml-2"></i>
</button> </button>
<div class="dropdown-menu p-2" <div class="tt-select-dropdown" :class="{ show: open }" @click.stop>
ref="dropdownMenu" <div class="dropdown-header">
:class="{ show: open }" <span>{{ label || 'Auswählen' }}</span>
style=" <button type="button" class="close-btn" @click="toggleDropdown">&times;</button>
min-width: 100%;
max-width: 400px;
max-height: 300px;
overflow-y: auto;
">
<input v-if="searchable"
ref="searchInput"
type="text"
class="form-control mb-2"
v-model="searchQuery"
:disabled="disabled"
placeholder="Suchen..."
@keydown.enter.prevent="handleEnter">
<div v-if="!filteredOptions.length && searchQuery" class="dropdown-item disabled text-muted">
Keine Ergebnisse gefunden.
</div> </div>
<div v-for="opt in filteredOptions" <div v-if="searchable" class="search-input-wrapper">
:key="opt.value" <input ref="searchInput" type="text" class="search-input"
class="dropdown-item px-2 py-1" v-model="searchQuery" :disabled="disabled" placeholder="Suchen..."
:class="{ disabled: opt.disabled }" @keydown.enter.prevent="handleEnter">
@click.stop>
<label class="d-flex align-items-center m-0 w-100" style="cursor: pointer;">
<input v-if="multiple"
type="checkbox"
class="form-check-input mr-2"
:checked="isSelected(opt)"
:disabled="opt.disabled"
@change.prevent="selectOption(opt)">
<input v-else
type="radio"
class="form-check-input mr-2"
:name="label"
:value="opt.value"
:checked="isSelected(opt)"
:disabled="opt.disabled"
@change.prevent="selectOption(opt)">
<span>
{{ opt.text }}<span v-if="suffix"> {{ suffix }}</span>
</span>
</label>
</div> </div>
<ul class="options-list" ref="optionsList">
<li v-if="!filteredOptions.length" class="no-results">
Keine Ergebnisse gefunden.
</li>
<li v-for="opt in filteredOptions" :key="opt.value"
class="option-item"
:class="{ 'selected': isSelected(opt), 'disabled': opt.disabled }"
@click="selectOption(opt)">
<div class="option-label">
<input :type="multiple ? 'checkbox' : 'radio'"
:name="'option-' + _uid"
:value="opt.value"
:checked="isSelected(opt)"
:disabled="opt.disabled">
<span>{{ opt.text }}<span v-if="suffix"> {{ suffix }}</span></span>
</div>
<i v-if="isSelected(opt)" class="fas fa-check option-checkmark"></i>
</li>
</ul>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -187,6 +187,7 @@ Vue.component('tt-table-crud', {
tableConfig() { tableConfig() {
return { return {
key: this.crudConfig.key, key: this.crudConfig.key,
customRowClass: this.crudConfig.customRowClass,
tableHeader: this.crudConfig.tableHeader, tableHeader: this.crudConfig.tableHeader,
headers: this.crudConfig.columns.filter(column => column.table !== false).map(column => { headers: this.crudConfig.columns.filter(column => column.table !== false).map(column => {
return {text: column.text, key: column.key, ...column.table, filterOptions: column?.table?.filterOptions ?? column?.modal?.items ?? [], priority: column.priority} return {text: column.text, key: column.key, ...column.table, filterOptions: column?.table?.filterOptions ?? column?.modal?.items ?? [], priority: column.priority}