Rml workorder/v2 need improvements
This commit is contained in:
@@ -5,26 +5,20 @@ class RMLWorkorderModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public int $preorderId;
|
||||
public ?int $companyId;
|
||||
public ?int $clusterId;
|
||||
public string $status;
|
||||
public ?int $assignmentDate;
|
||||
public ?int $deadlineDate;
|
||||
public ?int $appointmentDate;
|
||||
public int $create;
|
||||
public int $createBy;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
// This method remains unchanged as requested.
|
||||
public static function getWorkordersByUrgency(string $urgency, ?int $companyId = null): array {
|
||||
$db = self::getDB();
|
||||
$table = self::getFullyQualifiedTable();
|
||||
$now = time();
|
||||
$whereClause = "WHERE status IN ('assigned', 'scheduled')";
|
||||
|
||||
$whereClause = "WHERE status IN ('assigned', 'scheduled', 'correction_requested')";
|
||||
|
||||
if ($companyId) {
|
||||
$whereClause .= " AND companyId = " . intval($companyId);
|
||||
}
|
||||
@@ -32,7 +26,7 @@ class RMLWorkorderModel extends TTCrudBaseModel {
|
||||
switch ($urgency) {
|
||||
case 'red': // Less than 1 week left or overdue
|
||||
$redDate = strtotime('+1 week');
|
||||
$whereClause .= " AND deadlineDate < $redDate";
|
||||
$whereClause .= " AND deadlineDate IS NOT NULL AND deadlineDate < $redDate";
|
||||
break;
|
||||
case 'yellow': // Between 1 and 3 weeks left
|
||||
$yellowDateStart = strtotime('+1 week');
|
||||
@@ -41,7 +35,7 @@ class RMLWorkorderModel extends TTCrudBaseModel {
|
||||
break;
|
||||
case 'green': // More than 3 weeks left
|
||||
$greenDate = strtotime('+3 weeks');
|
||||
$whereClause .= " AND deadlineDate > $greenDate";
|
||||
$whereClause .= " AND deadlineDate > $greenDate";
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
@@ -56,4 +50,192 @@ class RMLWorkorderModel extends TTCrudBaseModel {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,27 @@ class RMLWorkorderAdminController extends TTCrud
|
||||
protected array $columns = [
|
||||
['key' => 'id', 'text' => 'Auftrag-Nr.', 'table' => ['sortable' => true]],
|
||||
['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' => 'status', 'text' => 'Status', 'modal' => false, 'table' => ['filter' => 'iconSelect', 'filterOptions' => [
|
||||
['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'],
|
||||
['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'],
|
||||
['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' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'],
|
||||
]]],
|
||||
['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()
|
||||
{
|
||||
$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();
|
||||
Helper::renderVue($this, 'RMLWorkorderAdmin', $this->headerTitle, [
|
||||
"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);
|
||||
$pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10];
|
||||
$filters = $json['filters'] ?? [];
|
||||
$order = $json['order'] ?? ['key' => 'id', 'order' => 'DESC'];
|
||||
$order = $json['order'] ?? [];
|
||||
|
||||
// Custom filter logic for preorderInfo
|
||||
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);
|
||||
$allowedCampaignIds = Helper::getPreorderCampaignFromUser($this->user);
|
||||
|
||||
if (!empty($preorderIds)) {
|
||||
$filters['preorderId'] = $preorderIds;
|
||||
} else {
|
||||
// No preorders found, so no workorders will be found
|
||||
$filters['id'] = -1;
|
||||
}
|
||||
if (empty($allowedCampaignIds)) {
|
||||
self::returnJson([
|
||||
'rows' => [],
|
||||
'pagination' => array_merge($pagination, ['total_rows' => 0, 'total_pages' => 0, 'filtered_available' => 0])
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$workorders = RMLWorkorderModel::getAll($filters, $pagination['per_page'], ($pagination['page'] - 1) * $pagination['per_page'], $order);
|
||||
$totalCount = RMLWorkorderModel::count($filters);
|
||||
|
||||
$rows = [];
|
||||
foreach($workorders as $workorder) {
|
||||
$limit = $pagination['per_page'];
|
||||
$offset = ($pagination['page'] - 1) * $limit;
|
||||
|
||||
$workorders = RMLWorkorderModel::getAdminWorkorders($filters, $limit, $offset, $order, $allowedCampaignIds);
|
||||
$totalCount = RMLWorkorderModel::countAdminWorkorders($filters, $allowedCampaignIds);
|
||||
|
||||
$rows = array_map(function($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>" .
|
||||
"<strong>Anschluss:</strong> {$anschlussadresse}<br>" .
|
||||
"<strong>OAID:</strong> <span class='text-pink'>{$preorder->oaid}</span>";
|
||||
"<strong>Anschluss:</strong> {$anschlussadresse}<br>" .
|
||||
"<strong>OAID:</strong> <span class='text-pink'>{$row['oaid']}</span>";
|
||||
|
||||
if($workorder->companyId) {
|
||||
$company = RMLWorkorderCompanyModel::get($workorder->companyId);
|
||||
$row['companyName'] = $company->name ?? 'N/A';
|
||||
} else {
|
||||
$row['companyName'] = 'Nicht zugewiesen';
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
$row['companyName'] ??= 'Nicht zugewiesen';
|
||||
$row['deadlineDateFormatted'] = $row['deadlineDate'] ? date('d.m.Y', $row['deadlineDate']) : 'Keine Deadline';
|
||||
$row['daysUntilDeadline'] = $row['deadlineDate'] ? ceil(($row['deadlineDate'] - time()) / (60 * 60 * 24)) : null;
|
||||
|
||||
unset($row['customerName'], $row['customerCompany'], $row['street'], $row['hausnummer'], $row['stiege'], $row['oaid'], $row['apartment'], $row['plz'], $row['city']);
|
||||
|
||||
return $row;
|
||||
}, $workorders);
|
||||
|
||||
self::returnJson([
|
||||
'rows' => $rows,
|
||||
@@ -95,7 +89,7 @@ class RMLWorkorderAdminController extends TTCrud
|
||||
'page' => $pagination['page'],
|
||||
'per_page' => $pagination['per_page'],
|
||||
'total_rows' => $totalCount,
|
||||
'total_pages' => ceil($totalCount / $pagination['per_page']),
|
||||
'total_pages' => ceil($totalCount / $limit),
|
||||
'filtered_available' => $totalCount
|
||||
]
|
||||
]);
|
||||
@@ -109,6 +103,7 @@ class RMLWorkorderAdminController extends TTCrud
|
||||
if (!RMLWorkorderModel::getFirst(['preorderId' => $preorder->id])) {
|
||||
RMLWorkorderModel::create([
|
||||
'preorderId' => $preorder->id,
|
||||
'clusterId' => $preorder->preordercampaign_id,
|
||||
'status' => 'new',
|
||||
'create' => time(),
|
||||
'createBy' => $this->user->id
|
||||
@@ -123,35 +118,112 @@ class RMLWorkorderAdminController extends TTCrud
|
||||
|
||||
$workorder = RMLWorkorderModel::get($post['workorderId']);
|
||||
if (!$workorder) self::sendError("Workorder not found.");
|
||||
|
||||
|
||||
$workorder->companyId = $post['companyId'];
|
||||
$workorder->status = 'assigned';
|
||||
$workorder->assignmentDate = time();
|
||||
$workorder->deadlineDate = strtotime('+6 weeks');
|
||||
$workorder->deadlineDate = $post['deadlineDate'] ?? strtotime('+6 weeks');
|
||||
|
||||
RMLWorkorderModel::update((array)$workorder);
|
||||
|
||||
|
||||
self::returnJson(['success' => true, 'message' => 'Auftrag erfolgreich zugewiesen.']);
|
||||
}
|
||||
|
||||
protected function getDocumentationAction() {
|
||||
if(empty($this->request->workorderId)) self::sendError("Workorder ID missing.");
|
||||
|
||||
|
||||
$docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC']);
|
||||
$users = UserModel::search(['employee' => true]);
|
||||
$userMap = array_reduce($users, fn($carry, $user) => $carry + [$user->id => $user->name], []);
|
||||
$journals = RMLWorkorderJournalModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'DESC']);
|
||||
$users = UserModel::search();
|
||||
|
||||
foreach($docs as $doc) {
|
||||
$file = new File($doc->fileId);
|
||||
$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() {
|
||||
$companies = RMLWorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
||||
$items = array_map(fn($c) => ['value' => $c->id, 'text' => $c->name], $companies);
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,12 +13,12 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'],
|
||||
['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'],
|
||||
['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' => 'completed', 'text' => 'Abgeschlossen', 'icon' => 'fas fa-check-double text-secondary'],
|
||||
]]],
|
||||
['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 array $additionalJSVariables = ['COMPANY_ID' => '0'];
|
||||
@@ -46,40 +46,38 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
$json = json_decode(file_get_contents('php://input'), true);
|
||||
$pagination = $json['pagination'] ?? ['page' => 1, 'per_page' => 10];
|
||||
$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]);
|
||||
if(!$company) self::sendError("Company not found for user.", 403);
|
||||
$filters['companyId'] = $company->id;
|
||||
|
||||
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;
|
||||
}
|
||||
if (!$company) {
|
||||
self::sendError("Company not found for user.", 403);
|
||||
}
|
||||
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);
|
||||
$totalCount = RMLWorkorderModel::count($filters);
|
||||
|
||||
$rows = [];
|
||||
foreach($workorders as $workorder) {
|
||||
// Format rows for the frontend
|
||||
$rows = array_map(function($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([
|
||||
'rows' => $rows,
|
||||
@@ -92,7 +90,6 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getWorkorderByIdAction() {
|
||||
$id = $this->request->id;
|
||||
if(!$id) self::sendError("ID missing");
|
||||
@@ -173,22 +170,30 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
]);
|
||||
$uploadCount++;
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());exit;
|
||||
// Log error but continue with other files
|
||||
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() {
|
||||
if(empty($this->request->workorderId)) self::sendError("Workorder ID missing.");
|
||||
|
||||
// Order by creation date to ensure consistent numbering (_1, _2, etc.)
|
||||
$docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $this->request->workorderId], null, 0, ['key' => 'create', 'order' => 'ASC']);
|
||||
|
||||
private function getFormattedDocs($workorderId) {
|
||||
$docs = RMLWorkorderDocumentationModel::getAll(['workorderId' => $workorderId], null, 0, ['key' => 'create', 'order' => 'ASC']);
|
||||
$responseDocs = [];
|
||||
$typeCounts = [];
|
||||
|
||||
@@ -202,8 +207,6 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
|
||||
foreach($docs as $doc) {
|
||||
$file = new File($doc->fileId);
|
||||
|
||||
// Increment counter for the specific document type
|
||||
$documentTypeKey = $doc->documentType;
|
||||
if (!isset($typeCounts[$documentTypeKey])) {
|
||||
$typeCounts[$documentTypeKey] = 1;
|
||||
@@ -211,23 +214,37 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
$typeCounts[$documentTypeKey]++;
|
||||
}
|
||||
|
||||
// Construct the new filename using the original key
|
||||
$originalFilename = $file->orig_filename ?? $file->filename;
|
||||
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
|
||||
$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[] = [
|
||||
'id' => $doc->fileId,
|
||||
'id' => $doc->id,
|
||||
'fileId' => $doc->fileId,
|
||||
'fileName' => $newFilename,
|
||||
'documentType' => $documentTypeKey,
|
||||
'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() {
|
||||
$post = json_decode(file_get_contents('php://input'), true);
|
||||
@@ -241,4 +258,74 @@ class RMLWorkorderCompanyController extends TTCrud
|
||||
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
application/RMLWorkorderJournal/RMLWorkorderJournalModel.php
Normal file
11
application/RMLWorkorderJournal/RMLWorkorderJournalModel.php
Normal 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;
|
||||
}
|
||||
14
db/migrations/20250723204001_CreateRmlWorkorderTables.php
Normal file
14
db/migrations/20250723204001_CreateRmlWorkorderTables.php
Normal 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;
|
||||
@@ -11,49 +11,75 @@ class Helper {
|
||||
public static function generateFilterCondition($filterValue, $columnName, bool $exactMatch = false): string {
|
||||
$sql = "";
|
||||
|
||||
$quotedColumn = (strpos($columnName, '.') === false && strpos($columnName, '|') === false)
|
||||
? "`$columnName`"
|
||||
: $columnName;
|
||||
|
||||
if (is_array($filterValue)) {
|
||||
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'])) {
|
||||
$sql = " AND `$columnName` >= " . $filterValue['from'];
|
||||
$sql = " AND $quotedColumn >= " . $filterValue['from'];
|
||||
} elseif (isset($filterValue['to'])) {
|
||||
$sql = " AND `$columnName` <= " . $filterValue['to'];
|
||||
$sql = " AND $quotedColumn <= " . $filterValue['to'];
|
||||
} else if (isset($filterValue['exact'])) {
|
||||
$sql = " AND `$columnName` = " . "'{$filterValue['exact']}'";
|
||||
$sql = " AND $quotedColumn = " . "'{$filterValue['exact']}'";
|
||||
} else if (!empty($filterValue)) {
|
||||
$sql = " AND `$columnName` IN ('" . implode("','", $filterValue) . "')";
|
||||
$sql = " AND $quotedColumn IN ('" . implode("','", $filterValue) . "')";
|
||||
}
|
||||
} else if ($filterValue === "0" || $filterValue === "1") {
|
||||
$sql .= " AND `$columnName` = " . $filterValue;
|
||||
$sql .= " AND $quotedColumn = " . $filterValue;
|
||||
} else if ($filterValue === null) {
|
||||
$sql .= " AND `$columnName` IS NULL";
|
||||
$sql .= " AND $quotedColumn IS NULL";
|
||||
} else if ($filterValue === '!NULL') {
|
||||
$sql .= " AND `$columnName` IS NOT NULL";
|
||||
$sql .= " AND $quotedColumn IS NOT NULL";
|
||||
} else if (!empty($filterValue)) {
|
||||
if ($exactMatch) {
|
||||
$sql .= " AND `$columnName` = '" . $filterValue . "'";
|
||||
$sql .= " AND $quotedColumn = '" . $filterValue . "'";
|
||||
} else if (strpos($columnName, "|") !== false) {
|
||||
foreach (explode(" ", $filterValue) as $item)
|
||||
$sql .= " AND CONCAT(" . join(",", explode("|", $columnName)) . ") LIKE '%" . $item . "%'";
|
||||
$columns = explode("|", $columnName);
|
||||
|
||||
// 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] === "%") {
|
||||
$sql .= " AND `$columnName` LIKE '" . $filterValue . "'";
|
||||
$sql .= " AND $quotedColumn LIKE '" . addslashes($filterValue) . "'";
|
||||
} else if ($filterValue[strlen($filterValue) - 1] === "%") {
|
||||
$sql .= " AND `$columnName` LIKE '" . $filterValue . "'";
|
||||
$sql .= " AND $quotedColumn LIKE '" . addslashes($filterValue) . "'";
|
||||
} else if ($filterValue[0] === "!") {
|
||||
$sql .= " AND `$columnName` NOT LIKE '%" . substr($filterValue, 1) . "%'";
|
||||
$sql .= " AND $quotedColumn NOT LIKE '%" . addslashes(substr($filterValue, 1)) . "%'";
|
||||
} else {
|
||||
$filterItems = explode(" ", $filterValue);
|
||||
foreach ($filterItems as $item) {
|
||||
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
|
||||
$escapedItem = addslashes($item); // Basic escaping
|
||||
$sql .= " AND $quotedColumn LIKE '%" . $escapedItem . "%'";
|
||||
}
|
||||
}
|
||||
} else if ($filterValue === 0) {
|
||||
$sql .= " AND `$columnName` = 0";
|
||||
$sql .= " AND $quotedColumn = 0";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
27
public/js/pages/RMLWorkorderAdmin/RMLWorkorderAdmin.css
Normal file
27
public/js/pages/RMLWorkorderAdmin/RMLWorkorderAdmin.css
Normal 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 */
|
||||
}
|
||||
@@ -1,70 +1,151 @@
|
||||
// RMLWorkorderAdmin.js
|
||||
Vue.component('r-m-l-workorder-admin', {
|
||||
template: `
|
||||
<tt-card>
|
||||
<assign-company-modal
|
||||
v-if="assignModalWorkorderId"
|
||||
:workorder-id="assignModalWorkorderId"
|
||||
@close="assignModalWorkorderId = null; $refs.table.$refs.table.refreshTable()"
|
||||
<tt-card>
|
||||
<div class="mb-2 d-flex align-items-center" v-if="workordersToAssign.length > 0">
|
||||
<span class="mr-3 font-weight-bold">{{ workordersToAssign.length }} Workorder(s) zuweisen:</span>
|
||||
<div style="width: 300px;">
|
||||
<tt-select
|
||||
class="mb-0"
|
||||
:options="companies"
|
||||
v-model="massAssignCompanyId"
|
||||
@input="massAssignCompanies"
|
||||
placeholder="Firma auswählen..."
|
||||
sm
|
||||
no-form-group
|
||||
/>
|
||||
|
||||
<documentation-viewer-modal
|
||||
v-if="docsModalWorkorderId"
|
||||
:workorder-id="docsModalWorkorderId"
|
||||
@close="docsModalWorkorderId = null"
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<tt-table-crud
|
||||
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()"
|
||||
/>
|
||||
|
||||
<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>
|
||||
|
||||
<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:deadlinedate="{ row }">
|
||||
{{ formatDate(row.deadlineDate) }}
|
||||
</template>
|
||||
|
||||
<template v-slot:appointmentdate="{ row }">
|
||||
{{ formatDate(row.appointmentDate) }}
|
||||
</template>
|
||||
|
||||
</tt-table-crud>
|
||||
</tt-card>
|
||||
</tt-table-crud>
|
||||
</tt-card>
|
||||
`,
|
||||
data() {
|
||||
return {
|
||||
assignModalWorkorderId: null,
|
||||
docsModalWorkorderId: null,
|
||||
workordersToAssign: [],
|
||||
editingWorkorderId: null,
|
||||
companies: [],
|
||||
massAssignCompanyId: null,
|
||||
massAssignLoading: false,
|
||||
crudConfig: {
|
||||
...window.TT_CONFIG.CRUD_CONFIG,
|
||||
additionalActions: [
|
||||
{
|
||||
"key": "assign",
|
||||
"title": "Firma zuweisen",
|
||||
"class": "fas fa-user-plus text-primary",
|
||||
"condition": (row) => row.status === 'new',
|
||||
},
|
||||
{
|
||||
"key": "view_docs",
|
||||
"title": "Dokumentation ansehen",
|
||||
"class": "fas fa-folder-open text-info",
|
||||
"condition": (row) => ['documented', 'completed'].includes(row.status),
|
||||
},
|
||||
]
|
||||
selectable: false,
|
||||
expandable: true,
|
||||
customRowClass: (row) => {
|
||||
const deadlineDate = moment.unix(row.deadlineDate);
|
||||
|
||||
if (['completed', 'new'].includes(row.status) || !deadlineDate.isValid()) {
|
||||
return 'tt-rml-workorder-irrelevant';
|
||||
}
|
||||
|
||||
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: []
|
||||
}
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getCompanies`);
|
||||
this.companies = response.data;
|
||||
},
|
||||
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) {
|
||||
const column = this.crudConfig.columns.find(c => c.key === 'status');
|
||||
return column.table.filterOptions.find(opt => opt.value === status) || {};
|
||||
@@ -72,6 +153,60 @@ Vue.component('r-m-l-workorder-admin', {
|
||||
formatDate(timestamp) {
|
||||
if (!timestamp) return '–';
|
||||
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'],
|
||||
computed: {
|
||||
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 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');
|
||||
if (daysLeft <= 7) return { color: '#dc3545', title: 'Dringend: Weniger als 1 Woche' };
|
||||
if (daysLeft <= 21) return { color: '#ffc107', title: 'Mittel: Weniger als 3 Wochen' };
|
||||
return { color: '#28a745', title: 'Im Plan: Mehr als 3 Wochen' };
|
||||
if (daysLeft <= 7) return {color: '#dc3545', title: 'Dringend: Weniger als 1 Woche'};
|
||||
if (daysLeft <= 21) return {color: '#ffc107', title: 'Mittel: Weniger 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">●</span>`
|
||||
});
|
||||
|
||||
Vue.component('assign-company-modal', {
|
||||
Vue.component('rml-documentation-viewer-admin', {
|
||||
props: ['workorderId'],
|
||||
template: `
|
||||
<tt-modal :show="true" title="Firma zuweisen" @submit="submit" @update:show="$emit('close')">
|
||||
<tt-select label="Firma" :options="companies" v-model="selectedCompanyId" sm row required />
|
||||
</tt-modal>
|
||||
<div class="p-3 bg-light">
|
||||
<div v-if="loading" class="text-center p-5"><i class="fas fa-spinner fa-spin fa-2x"></i></div>
|
||||
<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 } },
|
||||
async mounted() {
|
||||
const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getCompanies`);
|
||||
this.companies = response.data;
|
||||
data() {
|
||||
return {
|
||||
loading: true,
|
||||
correctionLoading: false,
|
||||
docs: [],
|
||||
journals: [],
|
||||
selectedDocs: [],
|
||||
correctionText: '',
|
||||
newJournalMessage: '',
|
||||
addingJournalEntry: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async submit() {
|
||||
if (!this.selectedCompanyId) return window.notify('error', 'Bitte eine Firma auswählen.');
|
||||
async fetchData() {
|
||||
this.loading = true;
|
||||
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,
|
||||
companyId: this.selectedCompanyId
|
||||
});
|
||||
if(response.data.success) {
|
||||
text: this.correctionText,
|
||||
fileIds: this.selectedDocs
|
||||
};
|
||||
const response = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/requestCorrection`, payload);
|
||||
if (response.data.success) {
|
||||
window.notify('success', response.data.message);
|
||||
this.$emit('close');
|
||||
this.correctionText = '';
|
||||
this.selectedDocs = [];
|
||||
await this.fetchData();
|
||||
this.$emit('workorder-updated');
|
||||
} else {
|
||||
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten.');
|
||||
window.notify('error', response.data.message);
|
||||
}
|
||||
} catch (e) {
|
||||
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.component('documentation-viewer-modal', {
|
||||
props: ['workorderId'],
|
||||
template: `
|
||||
<tt-modal :show="true" :title="'Dokumentation für Auftrag #' + workorderId" :save="false" :delete="false" @update:show="$emit('close')">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5>Hochgeladene Dokumente</h5>
|
||||
</div>
|
||||
<div v-if="loading" class="card-body text-center"><i class="fas fa-spinner fa-spin fa-2x"></i></div>
|
||||
<div v-else-if="!docs.length" class="card-body text-center text-muted">Keine Dokumente vorhanden.</div>
|
||||
<ul v-else class="list-group list-group-flush">
|
||||
<li v-for="doc in docs" :key="doc.id" class="list-group-item">
|
||||
<a :href="'/File/download?id=' + doc.fileId" target="_blank">
|
||||
<i class="fas fa-file-download mr-2"></i> {{ doc.fileName }}
|
||||
</a>
|
||||
<div class="text-muted small mt-1">
|
||||
<strong>Typ:</strong> {{ getDocTypeText(doc.documentType) }} <br/>
|
||||
<strong>Beschreibung:</strong> {{ doc.description || '-' }} <br/>
|
||||
<strong>Hochgeladen von:</strong> {{ doc.userName }} am {{ formatDate(doc.create) }}
|
||||
</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;
|
||||
this.correctionLoading = false;
|
||||
},
|
||||
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}/RMLWorkorderAdmin/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;
|
||||
}
|
||||
},
|
||||
formatDate(timestamp) {
|
||||
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() {
|
||||
this.fetchDocs();
|
||||
this.fetchData();
|
||||
}
|
||||
});
|
||||
30
public/js/pages/RMLWorkorderCompany/RMLWorkorderAdmin.css
Normal file
30
public/js/pages/RMLWorkorderCompany/RMLWorkorderAdmin.css
Normal 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;
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
// RMLWorkorderCompany.js
|
||||
|
||||
Vue.component('r-m-l-workorder-company', {
|
||||
template: `
|
||||
<tt-card>
|
||||
<schedule-appointment-modal
|
||||
v-if="scheduleModalWorkorderId"
|
||||
:workorder-id="scheduleModalWorkorderId"
|
||||
@close="scheduleModalWorkorderId = null; $refs.table.$refs.table.refreshTable()"
|
||||
/>
|
||||
|
||||
<tt-table-crud
|
||||
ref="table"
|
||||
@schedule="scheduleModalWorkorderId = $event.id"
|
||||
:crud-config="crudConfig"
|
||||
>
|
||||
<template v-slot:preorderinfo="{ row }">
|
||||
@@ -29,7 +21,16 @@ Vue.component('r-m-l-workorder-company', {
|
||||
</template>
|
||||
|
||||
<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 v-slot:expandedRow="{ row }">
|
||||
@@ -44,18 +45,24 @@ Vue.component('r-m-l-workorder-company', {
|
||||
`,
|
||||
data() {
|
||||
return {
|
||||
scheduleModalWorkorderId: null,
|
||||
crudConfig: {
|
||||
...window.TT_CONFIG.CRUD_CONFIG,
|
||||
expandable: true,
|
||||
additionalActions: [
|
||||
{
|
||||
"key": "schedule",
|
||||
"title": "Termin festlegen",
|
||||
"class": "fas fa-calendar-plus text-primary",
|
||||
"condition": (row) => row.status === 'assigned',
|
||||
customRowClass: (row) => {
|
||||
const deadlineDate = moment.unix(row.deadlineDate);
|
||||
|
||||
if (['completed', 'new'].includes(row.status) || !deadlineDate.isValid()) {
|
||||
return 'tt-rml-workorder-irrelevant';
|
||||
}
|
||||
]
|
||||
|
||||
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) {
|
||||
if (!timestamp) return '–';
|
||||
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">●</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', {
|
||||
props: ['workorderId'],
|
||||
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-else class="row">
|
||||
<div class="col-lg-4 mb-3 mb-lg-0">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Benötigte Dokumente</h5>
|
||||
<ul class="list-unstyled">
|
||||
<li v-for="docType in requiredDocTypes" :key="docType.value" class="mb-2 d-flex align-items-center">
|
||||
<i :class="isUploaded(docType.value) ? 'fas fa-check-circle text-success' : 'far fa-circle text-muted'" class="fa-fw mr-2"></i>
|
||||
<span>{{ docType.text }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<tt-button
|
||||
text="Auftrag abschließen"
|
||||
@click="completeWorkorder"
|
||||
:disabled="!canComplete || workorder.status === 'completed'"
|
||||
:loading="completing"
|
||||
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>
|
||||
<div v-if="workorder.status === 'completed'" class="alert alert-secondary text-center mt-2 p-2">
|
||||
Auftrag bereits abgeschlossen.
|
||||
<div>
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Benötigte Dokumente</h5>
|
||||
<ul class="list-unstyled">
|
||||
<li v-for="docType in requiredDocTypes" :key="docType.value" class="mb-2 d-flex align-items-center">
|
||||
<i :class="isUploaded(docType.value) ? 'fas fa-check-circle text-success' : 'far fa-circle text-muted'" class="fa-fw mr-2"></i>
|
||||
<span>{{ docType.text }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<tt-button
|
||||
text="Auftrag abschließen"
|
||||
@click="completeWorkorder"
|
||||
:disabled="!canComplete || workorder.status === 'completed'"
|
||||
:loading="completing"
|
||||
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>
|
||||
<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>
|
||||
@@ -162,15 +181,30 @@ Vue.component('documentation-manager', {
|
||||
<tt-input label="Beschreibung" v-model="uploadData.description" sm row placeholder="Optional"/>
|
||||
<div class="form-group row">
|
||||
<label class="col-form-label col-sm-4 col-form-label-sm">Dateien</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="file" class="form-control-file form-control-sm" @change="handleFileUpload" ref="fileInput" multiple />
|
||||
<div class="col-sm-8 p-0">
|
||||
<input type="file" class="form-control-file form-control-sm p-0" @change="handleFileUpload" ref="fileInput" multiple accept="image/*,.pdf,.doc,.docx" />
|
||||
</div>
|
||||
</div>
|
||||
<tt-button text="Hochladen" @click="uploadFiles" :loading="uploading" additional-class="btn-primary float-right" icon="fas fa-upload" />
|
||||
</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>
|
||||
@@ -182,6 +216,9 @@ Vue.component('documentation-manager', {
|
||||
uploading: false,
|
||||
completing: false,
|
||||
uploadedFiles: [],
|
||||
journals: [],
|
||||
newJournalMessage: '',
|
||||
addingJournalEntry: false,
|
||||
uploadData: {
|
||||
files: [],
|
||||
documentType: 'photo_before',
|
||||
@@ -199,9 +236,40 @@ Vue.component('documentation-manager', {
|
||||
computed: {
|
||||
canComplete() {
|
||||
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: {
|
||||
formatDate(timestamp) {
|
||||
if (!timestamp) return '–';
|
||||
return window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm');
|
||||
},
|
||||
async loadWorkorder() {
|
||||
this.loadingWorkorder = true;
|
||||
try {
|
||||
@@ -218,7 +286,8 @@ Vue.component('documentation-manager', {
|
||||
async fetchDocs() {
|
||||
try {
|
||||
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) {
|
||||
window.notify('error', 'Dokumente konnten nicht geladen werden.');
|
||||
}
|
||||
@@ -245,8 +314,9 @@ Vue.component('documentation-manager', {
|
||||
this.$refs.fileInput.value = '';
|
||||
this.uploadData.files = [];
|
||||
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 {
|
||||
window.notify('error', response.data.error || 'Upload fehlgeschlagen.');
|
||||
}
|
||||
@@ -271,9 +341,55 @@ Vue.component('documentation-manager', {
|
||||
}
|
||||
this.completing = false;
|
||||
},
|
||||
getDocTypeText(type) {
|
||||
const found = this.requiredDocTypes.find(t => t.value === type);
|
||||
return found ? found.text : type;
|
||||
async deleteDocumentation(file) {
|
||||
try {
|
||||
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() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* tt-file-gallery.css */
|
||||
.tt-file-gallery-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
@@ -13,11 +14,18 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tt-file-gallery-thumbnail {
|
||||
.tt-file-gallery-thumbnail-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
object-fit: cover;
|
||||
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;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
@@ -30,8 +38,8 @@
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 40px; /* Adjust to not cover filename */
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
color: white;
|
||||
display: flex;
|
||||
@@ -43,13 +51,13 @@
|
||||
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;
|
||||
}
|
||||
|
||||
.tt-file-gallery-icon-container {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
@@ -58,18 +66,40 @@
|
||||
background-color: #f8f9fa;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.tt-file-gallery-item:hover .tt-file-gallery-icon-container {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
|
||||
.tt-file-gallery-filename {
|
||||
font-size: 0.8rem;
|
||||
margin-top: 0.5rem;
|
||||
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;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.tt-file-gallery-filename > i {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
|
||||
/* --- Fullscreen Viewer Styles --- */
|
||||
|
||||
.tt-fullscreen-overlay {
|
||||
|
||||
198
public/plugins/vue/tt-components/css/tt-select.css
Normal file
198
public/plugins/vue/tt-components/css/tt-select.css
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
// tt-file-gallery.js
|
||||
Vue.component('tt-file-gallery', {
|
||||
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() {
|
||||
return {
|
||||
fullscreenItem: null, // Holds the file being viewed
|
||||
fullscreenItem: null,
|
||||
currentImageIndex: 0,
|
||||
|
||||
// Zoom & Pan state
|
||||
editingFile: null,
|
||||
selectedFiles: [],
|
||||
zoom: 1,
|
||||
pan: { x: 0, y: 0 },
|
||||
isPanning: false,
|
||||
@@ -23,7 +27,6 @@ Vue.component('tt-file-gallery', {
|
||||
return this.fullscreenItem && this.isImage(this.fullscreenItem);
|
||||
},
|
||||
imageTransformStyle() {
|
||||
// Apply CSS transform for zoom and pan
|
||||
const { x, y } = this.pan;
|
||||
return {
|
||||
transform: `translate(${x}px, ${y}px) scale(${this.zoom})`,
|
||||
@@ -33,34 +36,33 @@ Vue.component('tt-file-gallery', {
|
||||
},
|
||||
fullscreenDownloadUrl() {
|
||||
if (!this.fullscreenItem) return '#';
|
||||
return `/File/download?id=${this.fullscreenItem.id}`;
|
||||
return `/File/download?id=${this.fullscreenItem.fileId}`;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// File type checks
|
||||
isImage(file) {
|
||||
return file.mimetype && file.mimetype.startsWith('image/');
|
||||
},
|
||||
isPdf(file) {
|
||||
return file.mimetype === 'application/pdf';
|
||||
},
|
||||
|
||||
// Get icon for non-image/pdf files
|
||||
isImage: file => file.mimetype && file.mimetype.startsWith('image/'),
|
||||
isPdf: file => file.mimetype === 'application/pdf',
|
||||
getFileIcon(file) {
|
||||
const extension = file.fileName?.split('.').pop().toLowerCase();
|
||||
switch (extension) {
|
||||
case 'doc':
|
||||
case 'docx': return 'fas fa-file-word text-primary';
|
||||
case 'xls':
|
||||
case 'xlsx': return 'fas fa-file-excel text-success';
|
||||
case 'zip':
|
||||
case 'rar': return 'fas fa-file-archive text-warning';
|
||||
case 'doc': case 'docx': return 'fas fa-file-word text-primary';
|
||||
case 'xls': 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';
|
||||
}
|
||||
},
|
||||
|
||||
// Viewer controls
|
||||
toggleSelection(fileId) {
|
||||
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) {
|
||||
if(this.editingFile) return;
|
||||
this.fullscreenItem = file;
|
||||
if (this.isImage(file)) {
|
||||
this.currentImageIndex = this.imageFiles.findIndex(img => img.id === file.id);
|
||||
@@ -68,9 +70,7 @@ Vue.component('tt-file-gallery', {
|
||||
this.resetZoomAndPan();
|
||||
this.$nextTick(() => { this.$refs.viewer?.focus(); });
|
||||
},
|
||||
closeViewer() {
|
||||
this.fullscreenItem = null;
|
||||
},
|
||||
closeViewer() { this.fullscreenItem = null; },
|
||||
navigateImage(direction) {
|
||||
const newIndex = this.currentImageIndex + direction;
|
||||
if (newIndex >= 0 && newIndex < this.imageFiles.length) {
|
||||
@@ -79,9 +79,8 @@ Vue.component('tt-file-gallery', {
|
||||
this.resetZoomAndPan();
|
||||
}
|
||||
},
|
||||
|
||||
// Event handlers for keyboard and clicks
|
||||
handleKeyDown(event) {
|
||||
event.stopPropagation();
|
||||
if (!this.fullscreenItem) return;
|
||||
switch (event.key) {
|
||||
case 'Escape': this.closeViewer(); break;
|
||||
@@ -89,24 +88,16 @@ Vue.component('tt-file-gallery', {
|
||||
case 'ArrowRight': this.isViewingImage && this.navigateImage(1); break;
|
||||
}
|
||||
},
|
||||
|
||||
// --- Zoom and Pan Methods ---
|
||||
resetZoomAndPan() {
|
||||
this.zoom = 1;
|
||||
this.pan = { x: 0, y: 0 };
|
||||
this.isPanning = false;
|
||||
this.zoom = 1; this.pan = { x: 0, y: 0 }; this.isPanning = false;
|
||||
},
|
||||
|
||||
// Mouse Wheel Zoom
|
||||
handleWheel(e) {
|
||||
if (!this.isViewingImage) return;
|
||||
e.preventDefault();
|
||||
const scaleFactor = 0.2;
|
||||
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) {
|
||||
if (this.zoom <= 1) return;
|
||||
e.preventDefault();
|
||||
@@ -119,79 +110,81 @@ Vue.component('tt-file-gallery', {
|
||||
this.pan.x = e.clientX - this.panStart.x;
|
||||
this.pan.y = e.clientY - this.panStart.y;
|
||||
},
|
||||
onPanEnd() {
|
||||
this.isPanning = false;
|
||||
},
|
||||
onPanEnd() { this.isPanning = false; },
|
||||
onTouchStart(e) { /* ... touch logic ... */ },
|
||||
onTouchMove(e) { /* ... touch logic ... */ },
|
||||
onTouchEnd(e) { /* ... touch logic ... */ },
|
||||
|
||||
// Touch Events for Mobile (Pinch-to-Zoom & Pan)
|
||||
onTouchStart(e) {
|
||||
if (this.zoom <= 1 && e.touches.length === 1) return;
|
||||
e.preventDefault();
|
||||
if (e.touches.length === 1) { // Pan
|
||||
this.isPanning = true;
|
||||
this.panStart.x = e.touches[0].clientX - this.pan.x;
|
||||
this.panStart.y = e.touches[0].clientY - this.pan.y;
|
||||
} else if (e.touches.length === 2) { // Zoom
|
||||
this.lastPinchDist = Math.hypot(
|
||||
e.touches[0].clientX - e.touches[1].clientX,
|
||||
e.touches[0].clientY - e.touches[1].clientY
|
||||
);
|
||||
startEdit(file, event) {
|
||||
event?.stopPropagation();
|
||||
this.editingFile = { ...file }; // create a copy for editing
|
||||
},
|
||||
cancelEdit(event) {
|
||||
console.log('Edit cancelled');
|
||||
event?.stopPropagation();
|
||||
this.editingFile = null;
|
||||
},
|
||||
saveEdit(event) {
|
||||
event?.stopPropagation();
|
||||
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: {
|
||||
fullscreenItem(newItem) {
|
||||
// Prevent body scroll when viewer is open
|
||||
document.body.style.overflow = newItem ? 'hidden' : '';
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<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-else class="card-body">
|
||||
<div class="tt-file-gallery-grid">
|
||||
<div v-for="file in files" :key="file.id" class="tt-file-gallery-item" @click="openViewer(file)">
|
||||
<template v-if="isImage(file)">
|
||||
<img :src="'/File/show?id=' + file.id + '&size=small'" class="tt-file-gallery-thumbnail" :alt="file.fileName">
|
||||
<div class="tt-file-gallery-overlay"><i class="fas fa-search-plus"></i></div>
|
||||
</template>
|
||||
<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.id" 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-filename" :title="file.fileName">{{ file.fileName }}</div>
|
||||
<div v-for="file in files" :key="file.id"
|
||||
class="tt-file-gallery-item"
|
||||
:class="[{ 'selected': selectable && selectedFiles.includes(file.id) }, file.class]"
|
||||
@click="openViewer(file)">
|
||||
|
||||
<div v-if="selectable" class="selection-indicator" @click.stop="toggleSelection(file.id)">
|
||||
<i :class="selectedFiles.includes(file.id) ? 'fas fa-check-circle text-primary' : 'far fa-circle text-muted'"></i>
|
||||
</div>
|
||||
|
||||
<div class="tt-file-gallery-thumbnail-wrapper">
|
||||
<template v-if="isImage(file)">
|
||||
<img :src="'/File/show?id=' + file.fileId + '&size=small'" class="tt-file-gallery-thumbnail" :alt="file.fileName">
|
||||
</template>
|
||||
<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>
|
||||
|
||||
<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 class="tt-fullscreen-toolbar">
|
||||
<a v-if="isViewingImage" :href="fullscreenDownloadUrl" download class="tt-fullscreen-btn" title="Download">
|
||||
@@ -199,33 +192,19 @@ Vue.component('tt-file-gallery', {
|
||||
</a>
|
||||
<button class="tt-fullscreen-btn" @click="closeViewer" title="Close"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
|
||||
<div class="tt-fullscreen-content" @click.self="closeViewer">
|
||||
<template v-if="isViewingImage">
|
||||
<div class="tt-fullscreen-image-wrapper"
|
||||
@wheel="handleWheel"
|
||||
@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 class="tt-fullscreen-image-wrapper" @wheel="handleWheel" @mousedown="onPanStart" @mousemove="onPanMove" @mouseup="onPanEnd" @mouseleave="onPanEnd">
|
||||
<img :src="'/File/show?id=' + fullscreenItem.fileId" class="tt-fullscreen-image" :style="imageTransformStyle" @click.stop />
|
||||
</div>
|
||||
</template>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<template v-if="isViewingImage">
|
||||
<button class="tt-fullscreen-nav-btn left" @click.stop="navigateImage(-1)" v-if="currentImageIndex > 0">
|
||||
<i class="fas fa-chevron-left"></i>
|
||||
</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>
|
||||
<button class="tt-fullscreen-nav-btn left" @click.stop="navigateImage(-1)" v-if="currentImageIndex > 0"><i class="fas fa-chevron-left"></i></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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,6 @@ Vue.component('tt-modal', {
|
||||
if (!newVal) {
|
||||
this.$emit('close')
|
||||
}
|
||||
// if show now is true then focus the first input element
|
||||
if (newVal) {
|
||||
this.$nextTick(() => {
|
||||
const input = this.$refs.modal.querySelector('input')
|
||||
|
||||
@@ -1,50 +1,42 @@
|
||||
Vue.component('tt-select', {
|
||||
props: {
|
||||
options: { type: Array, required: true },
|
||||
label: { type: String, default: null },
|
||||
required: { type: Boolean, default: false },
|
||||
value: { type: [String, Number, Array], default: null },
|
||||
disabled: { type: Boolean, default: false },
|
||||
suffix: { type: String, default: null },
|
||||
sm: { type: Boolean, default: false },
|
||||
row: { type: Boolean, default: false },
|
||||
multiple: { type: Boolean, default: false },
|
||||
searchable: { type: Boolean, default: true }
|
||||
options: {type: Array, required: true},
|
||||
label: {type: String, default: null},
|
||||
required: {type: Boolean, default: false},
|
||||
value: {type: [String, Number, Array], default: null},
|
||||
disabled: {type: Boolean, default: false},
|
||||
suffix: {type: String, default: null},
|
||||
sm: {type: Boolean, default: false},
|
||||
row: {type: Boolean, default: false},
|
||||
multiple: {type: Boolean, default: false},
|
||||
searchable: {type: Boolean, default: true}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
open: false,
|
||||
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: {
|
||||
// keep internal model in sync with external v-model
|
||||
value(newVal) {
|
||||
this.selected = this.multiple
|
||||
? (Array.isArray(newVal) ? [...newVal] : [])
|
||||
: newVal;
|
||||
this.selected = this.multiple ? (Array.isArray(newVal) ? [...newVal] : []) : newVal;
|
||||
},
|
||||
|
||||
// Enhancement: Handle focus and scroll on open
|
||||
open(isOpen) {
|
||||
if (isOpen) {
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.dropdownMenu) {
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
if (!isOpen) {
|
||||
this.searchQuery = ''; // Reset search on close
|
||||
return;
|
||||
}
|
||||
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: {
|
||||
// normalize all options to { value, text, disabled }
|
||||
normalizedOptions() {
|
||||
return this.options.map(opt => {
|
||||
if (opt !== null && typeof opt === 'object') {
|
||||
return {
|
||||
value: opt.value,
|
||||
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)
|
||||
return this.options.map(opt =>
|
||||
(opt !== null && typeof opt === 'object')
|
||||
? {value: opt.value, text: opt.text, disabled: !!opt.disabled}
|
||||
: {value: opt, text: String(opt), disabled: false}
|
||||
);
|
||||
},
|
||||
|
||||
// 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() {
|
||||
if (this.multiple) {
|
||||
const arr = Array.isArray(this.selected) ? this.selected : [];
|
||||
const count = arr.length;
|
||||
if (count === 0) return '';
|
||||
if (count === 1) {
|
||||
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`;
|
||||
const addSuffix = text => text ? `${text}${this.suffix ? ` ${this.suffix}` : ''}` : '';
|
||||
|
||||
if (!this.multiple) {
|
||||
const opt = this.normalizedOptions.find(o => o.value === this.selected);
|
||||
return opt ? addSuffix(opt.text) : 'Auswählen...';
|
||||
}
|
||||
// single select
|
||||
const sel = this.normalizedOptions.find(o => o.value === this.selected);
|
||||
return sel
|
||||
? sel.text + (this.suffix ? ' ' + this.suffix : '')
|
||||
: '';
|
||||
|
||||
const count = Array.isArray(this.selected) ? this.selected.length : 0;
|
||||
if (count === 0) return 'Auswählen...';
|
||||
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) {
|
||||
if (!this.$el.contains(e.target)) {
|
||||
if (this.$el && !this.$el.contains(e.target)) {
|
||||
this.open = false;
|
||||
}
|
||||
},
|
||||
@@ -129,111 +108,80 @@ Vue.component('tt-select', {
|
||||
|
||||
selectOption(opt) {
|
||||
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;
|
||||
this.$emit('input', arr);
|
||||
if (this.multiple) {
|
||||
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 {
|
||||
this.selected = opt.value;
|
||||
this.$emit('input', opt.value);
|
||||
this.open = false;
|
||||
this.open = false; // Close on selection for single mode
|
||||
}
|
||||
this.$emit('input', this.selected);
|
||||
},
|
||||
|
||||
// Enhancement: Handle Enter key press on search input
|
||||
handleEnter() {
|
||||
// 4. If search is active and only one result is left, select it
|
||||
if (this.searchQuery && this.filteredOptions.length === 1) {
|
||||
this.selectOption(this.filteredOptions[0]);
|
||||
// Ensure dropdown closes for both single and multi-select mode
|
||||
this.open = false;
|
||||
if (!this.multiple) this.open = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
template: `
|
||||
<div class="form-group" :class="{ row: row }">
|
||||
<label v-if="label"
|
||||
:for="label"
|
||||
:class="{
|
||||
'col-form-label': row,
|
||||
'col-sm-4': row,
|
||||
'col-form-label-sm': sm && row
|
||||
}">
|
||||
<div class="form-group" :class="[{ 'row': row }, 'tt-select-modern']">
|
||||
<label v-if="label" :for="'tt-select-' + _uid"
|
||||
:class="['col-form-label', { 'col-sm-4': row, 'col-form-label-sm': sm && row }]">
|
||||
{{ label }}
|
||||
</label>
|
||||
|
||||
<div :class="row ? 'col-sm-8 p-0' : ''">
|
||||
<div class="dropdown" :class="{ show: open }">
|
||||
<button type="button"
|
||||
class="btn btn-outline-secondary form-control"
|
||||
:class="{ 'form-control-sm': sm, 'btn-sm': sm }"
|
||||
<div :class="{ 'col-sm-8 p-0': row }">
|
||||
<div class="tt-select-container">
|
||||
<button type="button" class="tt-select-trigger"
|
||||
:id="'tt-select-' + _uid"
|
||||
:class="{ 'sm': sm, 'open': open }"
|
||||
:disabled="disabled"
|
||||
@click.stop="toggleDropdown"
|
||||
style="display:flex; align-items:center;">
|
||||
<span style="
|
||||
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>
|
||||
@click.stop="toggleDropdown">
|
||||
<span class="trigger-text" :class="{'placeholder': !hasSelection}">{{ displayText }}</span>
|
||||
<i class="fas fa-chevron-down trigger-arrow"></i>
|
||||
</button>
|
||||
|
||||
<div class="dropdown-menu p-2"
|
||||
ref="dropdownMenu"
|
||||
:class="{ show: open }"
|
||||
style="
|
||||
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 class="tt-select-dropdown" :class="{ show: open }" @click.stop>
|
||||
<div class="dropdown-header">
|
||||
<span>{{ label || 'Auswählen' }}</span>
|
||||
<button type="button" class="close-btn" @click="toggleDropdown">×</button>
|
||||
</div>
|
||||
|
||||
<div v-for="opt in filteredOptions"
|
||||
:key="opt.value"
|
||||
class="dropdown-item px-2 py-1"
|
||||
:class="{ disabled: opt.disabled }"
|
||||
@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 v-if="searchable" class="search-input-wrapper">
|
||||
<input ref="searchInput" type="text" class="search-input"
|
||||
v-model="searchQuery" :disabled="disabled" placeholder="Suchen..."
|
||||
@keydown.enter.prevent="handleEnter">
|
||||
</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>
|
||||
|
||||
@@ -187,6 +187,7 @@ Vue.component('tt-table-crud', {
|
||||
tableConfig() {
|
||||
return {
|
||||
key: this.crudConfig.key,
|
||||
customRowClass: this.crudConfig.customRowClass,
|
||||
tableHeader: this.crudConfig.tableHeader,
|
||||
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}
|
||||
|
||||
Reference in New Issue
Block a user