Compare commits
21 Commits
dev/tasks-
...
60d6b9e4b6
| Author | SHA1 | Date | |
|---|---|---|---|
| 60d6b9e4b6 | |||
| ee84734601 | |||
| 2bfb245a46 | |||
| 90dc71e1c3 | |||
| 35caac394c | |||
| bb855d1510 | |||
| 59b9440420 | |||
| 649a2bab9c | |||
| 9f8312b88b | |||
| e1204cd311 | |||
| 1ffe2d5d57 | |||
| f1f503af77 | |||
| 9b84ff1367 | |||
| 7be37bd30f | |||
| 2039f5d03d | |||
| 38c48861a9 | |||
| 30044e00e9 | |||
| 23027d54d7 | |||
| 5e10d19bbd | |||
| 1953df262c | |||
| ac40c7d949 |
@@ -35,7 +35,7 @@ COMMENT ON TABLE municipalities IS 'Configuration Per Municipality (Tenant) usin
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 3: Table "contributions"
|
||||
-- Citizen and Administration Contributions as Points, Lines, and
|
||||
-- Aitizen and Administration Contributions as Points, Lines, and
|
||||
-- Polygons stored together in one mixed-geometry Column.
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE contributions (
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
-- =====================================================================
|
||||
-- Migration 009: Tasks Module — Tasks with Reward System
|
||||
-- =====================================================================
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 1: Tasks Table
|
||||
-- Stores Tasks with Geometry, Moderation and Completion.
|
||||
-- Status Flow from pending to rejected or approved to completed to verified
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS tasks (
|
||||
task_id SERIAL PRIMARY KEY,
|
||||
municipality_id INTEGER NOT NULL REFERENCES municipalities(municipality_id),
|
||||
geom GEOMETRY(Geometry, 4326) NOT NULL,
|
||||
geom_type VARCHAR(10) NOT NULL CHECK (geom_type IN ('point', 'line', 'polygon')),
|
||||
category VARCHAR(50) NOT NULL,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
description TEXT DEFAULT '',
|
||||
points_reward INTEGER NOT NULL DEFAULT 25,
|
||||
author_name VARCHAR(100) NOT NULL,
|
||||
browser_id VARCHAR(36),
|
||||
photo_path VARCHAR(255),
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending'
|
||||
CHECK (status IN ('pending', 'rejected', 'approved', 'completed', 'verified')),
|
||||
address VARCHAR(255),
|
||||
|
||||
-- Completion Fields empty before completed
|
||||
completed_by_name VARCHAR(100),
|
||||
completed_by_browser VARCHAR(36),
|
||||
completion_photo VARCHAR(255),
|
||||
completion_comment TEXT,
|
||||
completed_at TIMESTAMP,
|
||||
|
||||
-- Counters updated via Triggers
|
||||
likes_count INTEGER NOT NULL DEFAULT 0,
|
||||
dislikes_count INTEGER NOT NULL DEFAULT 0,
|
||||
comment_count INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_tasks_municipality ON tasks(municipality_id);
|
||||
CREATE INDEX idx_tasks_status ON tasks(status);
|
||||
CREATE INDEX idx_tasks_category ON tasks(category);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 2: Citizen Points Table
|
||||
-- One Row per Completion. Leaderboard via SUM and GROUP BY.
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS user_points (
|
||||
points_id SERIAL PRIMARY KEY,
|
||||
municipality_id INTEGER NOT NULL REFERENCES municipalities(municipality_id),
|
||||
user_name VARCHAR(100) NOT NULL,
|
||||
points INTEGER NOT NULL DEFAULT 25,
|
||||
task_id INTEGER NOT NULL REFERENCES tasks(task_id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_user_points_municipality ON user_points(municipality_id);
|
||||
CREATE INDEX idx_user_points_user ON user_points(user_name);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 3: Adapts Votes Table for Tasks
|
||||
-- Either contribution_id OR task_id
|
||||
-- ---------------------------------------------------------------------
|
||||
ALTER TABLE votes
|
||||
ADD COLUMN task_id INTEGER REFERENCES tasks(task_id) ON DELETE CASCADE;
|
||||
|
||||
CREATE INDEX idx_votes_task ON votes(task_id);
|
||||
|
||||
-- Unique Vote per Browser per Task
|
||||
ALTER TABLE votes
|
||||
ADD CONSTRAINT votes_task_browser_unique
|
||||
UNIQUE (task_id, browser_id);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 4: Adapts Comments Table for Tasks
|
||||
-- Either contribution_id OR task_id
|
||||
-- ---------------------------------------------------------------------
|
||||
ALTER TABLE comments
|
||||
ADD COLUMN task_id INTEGER REFERENCES tasks(task_id) ON DELETE CASCADE;
|
||||
|
||||
CREATE INDEX idx_comments_task ON comments(task_id);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 5: Trigger Updated Timestamp for Tasks
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TRIGGER set_tasks_updated_at
|
||||
BEFORE UPDATE ON tasks
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_updated_at();
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 6: Trigger Vote Counts for Tasks
|
||||
-- Mirrors Pattern from Contributions.
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE OR REPLACE FUNCTION update_task_vote_counts()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
|
||||
IF NEW.task_id IS NOT NULL THEN
|
||||
UPDATE tasks SET
|
||||
likes_count = (SELECT COUNT(*) FROM votes WHERE task_id = NEW.task_id AND vote_type = 'like'),
|
||||
dislikes_count = (SELECT COUNT(*) FROM votes WHERE task_id = NEW.task_id AND vote_type = 'dislike')
|
||||
WHERE task_id = NEW.task_id;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF TG_OP = 'DELETE' OR (TG_OP = 'UPDATE' AND OLD.task_id IS NOT NULL) THEN
|
||||
UPDATE tasks SET
|
||||
likes_count = (SELECT COUNT(*) FROM votes WHERE task_id = OLD.task_id AND vote_type = 'like'),
|
||||
dislikes_count = (SELECT COUNT(*) FROM votes WHERE task_id = OLD.task_id AND vote_type = 'dislike')
|
||||
WHERE task_id = OLD.task_id;
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS trigger_update_task_vote_counts ON votes;
|
||||
|
||||
CREATE TRIGGER trigger_update_task_vote_counts
|
||||
AFTER INSERT OR DELETE OR UPDATE ON votes
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_task_vote_counts();
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 7: Trigger Comment Count for Tasks
|
||||
-- Mirrors Pattern from Contributions.
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE OR REPLACE FUNCTION update_task_comment_count()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
|
||||
IF NEW.task_id IS NOT NULL THEN
|
||||
UPDATE tasks
|
||||
SET comment_count = (
|
||||
SELECT COUNT(*) FROM comments
|
||||
WHERE task_id = NEW.task_id AND status = 'approved'
|
||||
)
|
||||
WHERE task_id = NEW.task_id;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF TG_OP = 'DELETE' OR (TG_OP = 'UPDATE' AND OLD.task_id IS NOT NULL) THEN
|
||||
UPDATE tasks
|
||||
SET comment_count = (
|
||||
SELECT COUNT(*) FROM comments
|
||||
WHERE task_id = OLD.task_id AND status = 'approved'
|
||||
)
|
||||
WHERE task_id = OLD.task_id;
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS trigger_update_task_comment_count ON comments;
|
||||
|
||||
CREATE TRIGGER trigger_update_task_comment_count
|
||||
AFTER INSERT OR DELETE OR UPDATE OF status ON comments
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_task_comment_count();
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 8: Views for QGIS
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE OR REPLACE VIEW tasks_points AS
|
||||
SELECT * FROM tasks WHERE geom_type = 'point';
|
||||
|
||||
CREATE OR REPLACE VIEW tasks_lines AS
|
||||
SELECT * FROM tasks WHERE geom_type = 'line';
|
||||
|
||||
CREATE OR REPLACE VIEW tasks_polygons AS
|
||||
SELECT * FROM tasks WHERE geom_type = 'polygon';
|
||||
@@ -228,7 +228,7 @@ $counts['total'] = count($all_contributions);
|
||||
<div id="contributions-container">
|
||||
<?php if (empty($all_contributions)): ?>
|
||||
<div class="empty-state">
|
||||
<i class="fa-solid fa-inbox" style="font-size:2rem;margin-bottom:8px;display:block;"></i>
|
||||
<i class="fa-solid fa-inbox"></i>
|
||||
Noch keine Beiträge vorhanden.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
@@ -381,7 +381,7 @@ $counts['total'] = count($all_contributions);
|
||||
<div id="comments-mod-container">
|
||||
<?php if (empty($all_comments)): ?>
|
||||
<div class="empty-state">
|
||||
<i class="fa-solid fa-comments" style="font-size:2rem;margin-bottom:8px;display:block;"></i>
|
||||
<i class="fa-solid fa-comments"></i>
|
||||
Noch keine Kommentare vorhanden.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
@@ -409,9 +409,9 @@ $counts['total'] = count($all_contributions);
|
||||
|
||||
<!-- Expanded Detail -->
|
||||
<div class="contribution-row-detail">
|
||||
<div style="padding:12px 0;">
|
||||
<div class="detail-block">
|
||||
<!-- Comment Content -->
|
||||
<div style="font-size:0.9rem;line-height:1.6;color:var(--color-text);margin-bottom:12px;">
|
||||
<div class="detail-block">
|
||||
<?= nl2br(htmlspecialchars($comment['content'])) ?>
|
||||
</div>
|
||||
<!-- Meta -->
|
||||
@@ -457,8 +457,8 @@ $counts['total'] = count($all_contributions);
|
||||
<!-- News Article Tab -->
|
||||
<!-- ========================================================= -->
|
||||
<div id="tab-news" class="page-tab-content" style="display:none;">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:20px;">
|
||||
<h2 style="margin:0;border:none;padding:0;"><i class="fa-solid fa-newspaper"></i> Neuigkeiten</h2>
|
||||
<div class="tab-header">
|
||||
<h2><i class="fa-solid fa-newspaper"></i> Neuigkeiten</h2>
|
||||
<button class="btn btn-approve" onclick="createNews()">
|
||||
<i class="fa-solid fa-plus"></i> Nachricht hinzufügen
|
||||
</button>
|
||||
@@ -466,7 +466,7 @@ $counts['total'] = count($all_contributions);
|
||||
|
||||
<?php if (empty($news_items)): ?>
|
||||
<div class="empty-state">
|
||||
<i class="fa-solid fa-newspaper" style="font-size:2rem;margin-bottom:8px;display:block;"></i>
|
||||
<i class="fa-solid fa-newspaper"></i>
|
||||
Noch keine Neuigkeiten veröffentlicht.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
@@ -475,7 +475,7 @@ $counts['total'] = count($all_contributions);
|
||||
<div class="contribution-row-header" onclick="toggleRow(this.parentElement)">
|
||||
<div class="contribution-row-summary">
|
||||
<span class="title"><?= htmlspecialchars($news['title']) ?></span>
|
||||
<span style="font-size:0.8rem;color:#999;">
|
||||
<span class="detail-block-meta">
|
||||
<?= date('d.m.Y', strtotime($news['published_at'])) ?>
|
||||
· <?= htmlspecialchars($news['author_name']) ?>
|
||||
</span>
|
||||
@@ -483,7 +483,7 @@ $counts['total'] = count($all_contributions);
|
||||
<i class="fa-solid fa-chevron-down collapse-icon"></i>
|
||||
</div>
|
||||
<div class="contribution-row-detail">
|
||||
<div style="padding:12px 0;font-size:0.9rem;line-height:1.6;color:#5a5a7a;">
|
||||
<div class="detail-block">
|
||||
<?= nl2br(htmlspecialchars($news['content'])) ?>
|
||||
</div>
|
||||
<div class="action-buttons">
|
||||
|
||||
@@ -17,7 +17,7 @@ require_once __DIR__ . '/db.php';
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Reads Action Parameter and Routes to correct Handler
|
||||
// Read Action Parameter and Route to correct Handler
|
||||
// ---------------------------------------------------------------------
|
||||
$input = get_input();
|
||||
$action = $input['action'] ?? '';
|
||||
@@ -59,27 +59,6 @@ switch ($action) {
|
||||
case 'update_comment':
|
||||
handle_update_comment($input);
|
||||
break;
|
||||
case 'read_tasks':
|
||||
handle_read_tasks($input);
|
||||
break;
|
||||
case 'create_task':
|
||||
handle_create_task($input);
|
||||
break;
|
||||
case 'update_task':
|
||||
handle_update_task($input);
|
||||
break;
|
||||
case 'delete_task':
|
||||
handle_delete_task($input);
|
||||
break;
|
||||
case 'complete_task':
|
||||
handle_complete_task($input);
|
||||
break;
|
||||
case 'verify_task':
|
||||
handle_verify_task($input);
|
||||
break;
|
||||
case 'read_leaderboard':
|
||||
handle_read_leaderboard($input);
|
||||
break;
|
||||
default:
|
||||
error_response('Unknown Action. Supported Actions are read, create, update, delete, vote.');
|
||||
}
|
||||
@@ -356,8 +335,8 @@ function handle_delete($input) {
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// VOTE: Likes or Dislikes Contributions or Tasks
|
||||
// Required: contribution_id or task_id, voter_name, vote_type
|
||||
// VOTE: Likes or Dislikes a Contribution
|
||||
// Required: contribution_id, voter_name, vote_type
|
||||
// Database Trigger automatically updates Likes and Dislikes Count
|
||||
// UNIQUE Constraint prevents duplicate Votes per Voter.
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -365,7 +344,7 @@ function handle_vote($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
// Validates Input
|
||||
$missing = validate_required($input, ['voter_name', 'vote_type']);
|
||||
$missing = validate_required($input, ['contribution_id', 'voter_name', 'vote_type']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
@@ -376,6 +355,13 @@ function handle_vote($input) {
|
||||
error_response('Invalid vote_type. Must be: ' . implode(', ', $valid_vote_types));
|
||||
}
|
||||
|
||||
// Checks if Contribution exists
|
||||
$stmt = $pdo->prepare("SELECT contribution_id FROM contributions WHERE contribution_id = :id");
|
||||
$stmt->execute([':id' => $input['contribution_id']]);
|
||||
if (!$stmt->fetch()) {
|
||||
error_response('Contribution not found.', 404);
|
||||
}
|
||||
|
||||
// Prepared SQL Statement
|
||||
try {
|
||||
// Checks if Voter already voted on this Contribution
|
||||
@@ -384,39 +370,11 @@ function handle_vote($input) {
|
||||
error_response('Browser ID required for Voting.');
|
||||
}
|
||||
|
||||
// Determines Vote Type
|
||||
$is_task = isset($input['task_id']) && $input['task_id'] !== '';
|
||||
|
||||
if ($is_task) {
|
||||
// Checks for Tasks
|
||||
$stmt = $pdo->prepare("SELECT task_id FROM tasks WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
if (!$stmt->fetch()) {
|
||||
error_response('Task not found.', 404);
|
||||
}
|
||||
|
||||
// Checks if Browser already voted on Task
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT vote_id, vote_type FROM votes
|
||||
WHERE task_id = :id AND browser_id = :bid
|
||||
WHERE contribution_id = :cid AND browser_id = :bid
|
||||
");
|
||||
$stmt->execute([':id' => $input['task_id'], ':bid' => $browser_id]);
|
||||
} else {
|
||||
// Checks for Contributions
|
||||
$stmt = $pdo->prepare("SELECT contribution_id FROM contributions WHERE contribution_id = :id");
|
||||
$stmt->execute([':id' => $input['contribution_id']]);
|
||||
if (!$stmt->fetch()) {
|
||||
error_response('Contribution not found.', 404);
|
||||
}
|
||||
|
||||
// Checks if Browser already voted on Contribution
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT vote_id, vote_type FROM votes
|
||||
WHERE contribution_id = :id AND browser_id = :bid
|
||||
");
|
||||
$stmt->execute([':id' => $input['contribution_id'], ':bid' => $browser_id]);
|
||||
}
|
||||
|
||||
$stmt->execute([':cid' => $input['contribution_id'], ':bid' => $browser_id]);
|
||||
$existing = $stmt->fetch();
|
||||
|
||||
if ($existing) {
|
||||
@@ -426,48 +384,36 @@ function handle_vote($input) {
|
||||
$stmt->execute([':vid' => $existing['vote_id']]);
|
||||
json_response(['message' => 'Vote removed.', 'action' => 'removed']);
|
||||
} else {
|
||||
// Different Vote Type — Removes old Vote before Inserting new one
|
||||
// Different Vote Type — Switches Vote
|
||||
$stmt = $pdo->prepare("DELETE FROM votes WHERE vote_id = :vid");
|
||||
$stmt->execute([':vid' => $existing['vote_id']]);
|
||||
$this_insert = true;
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO votes (contribution_id, voter_name, vote_type, browser_id)
|
||||
VALUES (:cid, :voter, :vtype, :bid)
|
||||
");
|
||||
$stmt->execute([
|
||||
':cid' => $input['contribution_id'],
|
||||
':voter' => $input['voter_name'],
|
||||
':vtype' => $input['vote_type'],
|
||||
':bid' => $browser_id
|
||||
]);
|
||||
json_response(['message' => 'Vote changed.', 'action' => 'changed'], 200);
|
||||
}
|
||||
} else {
|
||||
// No existing Vote — Inserts Vote
|
||||
$this_insert = true;
|
||||
}
|
||||
|
||||
if (!empty($this_insert)) {
|
||||
if ($is_task) {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO votes (task_id, voter_name, vote_type, browser_id)
|
||||
VALUES (:id, :voter, :vtype, :bid)
|
||||
");
|
||||
$stmt->execute([
|
||||
':id' => $input['task_id'],
|
||||
':voter' => $input['voter_name'],
|
||||
':vtype' => $input['vote_type'],
|
||||
':bid' => $browser_id
|
||||
]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO votes (contribution_id, voter_name, vote_type, browser_id)
|
||||
VALUES (:id, :voter, :vtype, :bid)
|
||||
VALUES (:cid, :voter, :vtype, :bid)
|
||||
");
|
||||
$stmt->execute([
|
||||
':id' => $input['contribution_id'],
|
||||
':cid' => $input['contribution_id'],
|
||||
':voter' => $input['voter_name'],
|
||||
':vtype' => $input['vote_type'],
|
||||
':bid' => $browser_id
|
||||
]);
|
||||
}
|
||||
|
||||
// Returns changed or created
|
||||
if ($existing) {
|
||||
json_response(['message' => 'Vote changed.', 'action' => 'changed'], 200);
|
||||
} else {
|
||||
json_response(['message' => 'Vote recorded.', 'action' => 'created'], 201);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
@@ -619,40 +565,26 @@ function handle_photo_upload($file) {
|
||||
// =====================================================================
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// READ COMMENTS: Loads Comments for Contributions or Tasks
|
||||
// Returns Comments sorted by Date (oldest first)
|
||||
// Required: contribution_id or task_id
|
||||
// READ COMMENTS: Loads Comments for a Contribution
|
||||
// Returns Comments sorted by Date (newest first)
|
||||
// Required: contribution_id
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_read_comments($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
// Checks for contribution_id or task_id
|
||||
if (empty($input['contribution_id']) && empty($input['task_id'])) {
|
||||
error_response('Either contribution_id or task_id is required.');
|
||||
$missing = validate_required($input, ['contribution_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
// Determines Vote Type
|
||||
$is_task = isset($input['task_id']) && $input['task_id'] !== '';
|
||||
|
||||
try {
|
||||
if ($is_task) {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT comment_id, task_id, author_name, browser_id, content, status, created_at
|
||||
FROM comments
|
||||
WHERE task_id = :id AND status = 'approved'
|
||||
ORDER BY created_at ASC
|
||||
");
|
||||
} else {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT comment_id, contribution_id, author_name, browser_id, content, status, created_at
|
||||
FROM comments
|
||||
WHERE contribution_id = :id AND status = 'approved'
|
||||
WHERE contribution_id = :cid AND status = 'approved'
|
||||
ORDER BY created_at ASC
|
||||
");
|
||||
}
|
||||
|
||||
// Prepared Statement
|
||||
$stmt->execute([':id' => $is_task ? $input['task_id'] : $input['contribution_id']]);
|
||||
$stmt->execute([':cid' => $input['contribution_id']]);
|
||||
$comments = $stmt->fetchAll();
|
||||
|
||||
json_response(['comments' => $comments, 'count' => count($comments)]);
|
||||
@@ -664,56 +596,37 @@ function handle_read_comments($input) {
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// CREATE COMMENT: Adds Comments Contributions or Tasks
|
||||
// Required: author_name, content, contribution_id or task_id
|
||||
// CREATE COMMENT: Adds Comments to Contributions
|
||||
// Required: contribution_id, author_name, content
|
||||
// Optional: browser_id
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_create_comment($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['author_name', 'content']);
|
||||
$missing = validate_required($input, ['contribution_id', 'author_name', 'content']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
// Checks for contribution_id or task_id
|
||||
if (empty($input['contribution_id']) && empty($input['task_id'])) {
|
||||
error_response('Either contribution_id or task_id is required.');
|
||||
}
|
||||
|
||||
// Validates Length
|
||||
// Validates Content Length
|
||||
if (strlen($input['content']) > 1000) {
|
||||
error_response('Comment too long. Maximum 1000 Characters.');
|
||||
}
|
||||
|
||||
// Determines Comment Type
|
||||
$is_task = isset($input['task_id']) && $input['task_id'] !== '';
|
||||
|
||||
if ($is_task) {
|
||||
// Checks for Tasks
|
||||
$stmt = $pdo->prepare("SELECT task_id FROM tasks WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
if (!$stmt->fetch()) {
|
||||
error_response('Task not found.', 404);
|
||||
}
|
||||
} else {
|
||||
// Checks for Contributions
|
||||
// Checks if Contribution exists
|
||||
$stmt = $pdo->prepare("SELECT contribution_id FROM contributions WHERE contribution_id = :id");
|
||||
$stmt->execute([':id' => $input['contribution_id']]);
|
||||
if (!$stmt->fetch()) {
|
||||
error_response('Contribution not found.', 404);
|
||||
}
|
||||
}
|
||||
|
||||
// Prepared Statement
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO comments (contribution_id, task_id, author_name, browser_id, content)
|
||||
VALUES (:cid, :tid, :author, :bid, :content)
|
||||
INSERT INTO comments (contribution_id, author_name, browser_id, content)
|
||||
VALUES (:cid, :author, :bid, :content)
|
||||
");
|
||||
$stmt->execute([
|
||||
':cid' => $is_task ? null : $input['contribution_id'],
|
||||
':tid' => $is_task ? $input['task_id'] : null,
|
||||
':cid' => $input['contribution_id'],
|
||||
':author' => $input['author_name'],
|
||||
':bid' => $input['browser_id'] ?? null,
|
||||
':content' => $input['content']
|
||||
@@ -797,386 +710,3 @@ function handle_update_comment($input) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// Action Handlers for Tasks
|
||||
// =====================================================================
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// READ TASKS: Loads Tasks as GeoJSON FeatureCollection
|
||||
// Required: municipality_id
|
||||
// Optional: status, browser_id
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_read_tasks($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['municipality_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
$sql = "SELECT *, ST_AsGeoJSON(geom) AS geojson
|
||||
FROM tasks
|
||||
WHERE municipality_id = :mid";
|
||||
$params = [':mid' => $input['municipality_id']];
|
||||
|
||||
// Status Filter
|
||||
$status = $input['status'] ?? 'visible';
|
||||
if ($status === 'visible') {
|
||||
$sql .= " AND status IN ('open', 'completed', 'verified')";
|
||||
} elseif ($status !== 'all') {
|
||||
$sql .= " AND status = :status";
|
||||
$params[':status'] = $status;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY created_at DESC";
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
|
||||
// Builds GeoJSON FeatureCollection
|
||||
$features = [];
|
||||
foreach ($rows as $row) {
|
||||
$geometry = json_decode($row['geojson']);
|
||||
unset($row['geom'], $row['geojson']);
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => $geometry,
|
||||
'properties' => $row
|
||||
];
|
||||
}
|
||||
|
||||
$result = [
|
||||
'type' => 'FeatureCollection',
|
||||
'features' => $features
|
||||
];
|
||||
|
||||
// User Votes for Tasks
|
||||
$browser_id = $input['browser_id'] ?? '';
|
||||
if ($browser_id !== '') {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT task_id, vote_type FROM votes
|
||||
WHERE browser_id = :bid AND task_id IS NOT NULL
|
||||
");
|
||||
$stmt->execute([':bid' => $browser_id]);
|
||||
$user_votes = [];
|
||||
foreach ($stmt->fetchAll() as $v) {
|
||||
$user_votes[$v['task_id']] = $v['vote_type'];
|
||||
}
|
||||
$result['user_votes'] = $user_votes;
|
||||
}
|
||||
|
||||
json_response($result);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// CREATE TASK: Inserts new Task with optional Photo
|
||||
// Required: municipality_id, geom, geom_type, category, title, author_name
|
||||
// Optional: description, browser_id, photo
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_create_task($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, [
|
||||
'municipality_id', 'geom', 'geom_type', 'category', 'title', 'author_name'
|
||||
]);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
$valid_geom_types = ['point', 'line', 'polygon'];
|
||||
if (!in_array($input['geom_type'], $valid_geom_types)) {
|
||||
error_response('Invalid Geometry Type.');
|
||||
}
|
||||
|
||||
$geojson = json_decode($input['geom']);
|
||||
if (!$geojson || !isset($geojson->type)) {
|
||||
error_response('Invalid GeoJSON.');
|
||||
}
|
||||
|
||||
// Handles optional Photo Upload
|
||||
$photo_path = null;
|
||||
if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) {
|
||||
$photo_path = handle_photo_upload($_FILES['photo']);
|
||||
if (!$photo_path) {
|
||||
error_response('Photo Upload failed. JPG, PNG, GIF and WebP up to 5 MB.');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO tasks
|
||||
(municipality_id, geom, geom_type, category, title, description, author_name, browser_id, photo_path)
|
||||
VALUES
|
||||
(:mid, ST_SetSRID(ST_GeomFromGeoJSON(:geom), 4326), :geom_type,
|
||||
:category, :title, :description, :author_name, :browser_id, :photo_path)
|
||||
");
|
||||
$stmt->execute([
|
||||
':mid' => $input['municipality_id'],
|
||||
':geom' => $input['geom'],
|
||||
':geom_type' => $input['geom_type'],
|
||||
':category' => $input['category'],
|
||||
':title' => $input['title'],
|
||||
':description' => $input['description'] ?? '',
|
||||
':author_name' => $input['author_name'],
|
||||
':browser_id' => $input['browser_id'] ?? null,
|
||||
':photo_path' => $photo_path
|
||||
]);
|
||||
|
||||
json_response([
|
||||
'message' => 'Task created successfully.',
|
||||
'task_id' => (int) $pdo->lastInsertId()
|
||||
], 201);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// UPDATE TASK: Updates existing Tasks or Status
|
||||
// Required: task_id
|
||||
// Optional: category, title, description, status, address
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_update_task($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['task_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
$updatable = ['category', 'title', 'description', 'status', 'address'];
|
||||
$set = [];
|
||||
$params = [':id' => $input['task_id']];
|
||||
|
||||
foreach ($updatable as $field) {
|
||||
if (isset($input[$field]) && $input[$field] !== '') {
|
||||
$set[] = "$field = :$field";
|
||||
$params[":$field"] = $input[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($set)) {
|
||||
error_response('No Fields to update.');
|
||||
}
|
||||
|
||||
if (isset($params[':status'])) {
|
||||
$valid = ['pending', 'rejected', 'open', 'completed', 'verified'];
|
||||
if (!in_array($params[':status'], $valid)) {
|
||||
error_response('Invalid Status.');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE tasks SET " . implode(', ', $set) . " WHERE task_id = :id");
|
||||
$stmt->execute($params);
|
||||
json_response(['message' => 'Task updated successfully.']);
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// DELETE TASK: Removes existing Tasks
|
||||
// Required: task_id
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_delete_task($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['task_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM tasks WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
json_response(['message' => 'Task deleted successfully.']);
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// COMPLETE TASK: Completes existing Tasks with Photo Proof
|
||||
// Required: task_id, author_name, browser_id
|
||||
// Required File: completion_photo
|
||||
// Optional: completion_comment
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_complete_task($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['task_id', 'author_name', 'browser_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
// Checks if Task exists and is open
|
||||
$stmt = $pdo->prepare("SELECT task_id, status FROM tasks WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
$task = $stmt->fetch();
|
||||
|
||||
if (!$task) {
|
||||
error_response('Task not found.', 404);
|
||||
}
|
||||
if ($task['status'] !== 'open') {
|
||||
error_response('Task is not available for Completion.');
|
||||
}
|
||||
|
||||
// Handles required Completion Photo
|
||||
if (!isset($_FILES['completion_photo']) || $_FILES['completion_photo']['error'] !== UPLOAD_ERR_OK) {
|
||||
error_response('Completion Photo is required.');
|
||||
}
|
||||
|
||||
$photo_path = handle_photo_upload($_FILES['completion_photo']);
|
||||
if (!$photo_path) {
|
||||
error_response('Photo Upload failed. JPG, PNG, GIF and WebP up to 5 MB.');
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE tasks SET
|
||||
status = 'completed',
|
||||
completed_by_name = :name,
|
||||
completed_by_browser = :browser,
|
||||
completion_photo = :photo,
|
||||
completion_comment = :comment,
|
||||
completed_at = NOW()
|
||||
WHERE task_id = :id
|
||||
");
|
||||
$stmt->execute([
|
||||
':id' => $input['task_id'],
|
||||
':name' => $input['author_name'],
|
||||
':browser' => $input['browser_id'],
|
||||
':photo' => $photo_path,
|
||||
':comment' => $input['completion_comment'] ?? ''
|
||||
]);
|
||||
|
||||
json_response(['message' => 'Task Completion submitted for Review.']);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// VERIFY TASK: Moderator confirms or rejects Completions
|
||||
// Required: task_id, action
|
||||
// Awards Points and sets Status if verified
|
||||
// Clears Completion Fields, resets Status if rejected
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_verify_task($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['task_id', 'verify_action']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
// Loads Task
|
||||
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
$task = $stmt->fetch();
|
||||
|
||||
if (!$task) {
|
||||
error_response('Task not found.', 404);
|
||||
}
|
||||
if ($task['status'] !== 'completed') {
|
||||
error_response('Task is not in completed State.');
|
||||
}
|
||||
|
||||
try {
|
||||
if ($input['verify_action'] === 'verify') {
|
||||
// Accepts Completion and Awards Points
|
||||
$stmt = $pdo->prepare("UPDATE tasks SET status = 'verified' WHERE task_id = :id");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
|
||||
// Awards Points to User
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO user_points (municipality_id, user_name, points, task_id)
|
||||
VALUES (:mid, :name, :points, :tid)
|
||||
");
|
||||
$stmt->execute([
|
||||
':mid' => $task['municipality_id'],
|
||||
':name' => $task['completed_by_name'],
|
||||
':points' => $task['points_reward'],
|
||||
':tid' => $input['task_id']
|
||||
]);
|
||||
|
||||
json_response(['message' => 'Task verified. Points awarded.']);
|
||||
|
||||
} elseif ($input['verify_action'] === 'reject') {
|
||||
// Rejects Completion and Clears Fields
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE tasks SET
|
||||
status = 'open',
|
||||
completed_by_name = NULL,
|
||||
completed_by_browser = NULL,
|
||||
completion_photo = NULL,
|
||||
completion_comment = NULL,
|
||||
completed_at = NULL
|
||||
WHERE task_id = :id
|
||||
");
|
||||
$stmt->execute([':id' => $input['task_id']]);
|
||||
|
||||
json_response(['message' => 'Completion rejected. Task is open again.']);
|
||||
|
||||
} else {
|
||||
error_response('Invalid Action. Must be: verify or reject.');
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// READ LEADERBOARD: Returns Citizen Leaderboard
|
||||
// Required: municipality_id
|
||||
// Optional: limit
|
||||
// ---------------------------------------------------------------------
|
||||
function handle_read_leaderboard($input) {
|
||||
$pdo = get_db();
|
||||
|
||||
$missing = validate_required($input, ['municipality_id']);
|
||||
if (!empty($missing)) {
|
||||
error_response('Missing Fields: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
$limit = min((int)($input['limit'] ?? 10), 50);
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT user_name,
|
||||
SUM(points) AS total_points,
|
||||
COUNT(*) AS tasks_completed
|
||||
FROM user_points
|
||||
WHERE municipality_id = :mid
|
||||
GROUP BY user_name
|
||||
ORDER BY total_points DESC
|
||||
LIMIT :lim
|
||||
");
|
||||
$stmt->bindValue(':mid', $input['municipality_id'], PDO::PARAM_INT);
|
||||
$stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
json_response(['leaderboard' => $stmt->fetchAll()]);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_response('Database Error: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,21 +111,3 @@ function get_categories() {
|
||||
'other' => ['label' => 'Sonstiges', 'faIcon' => 'fa-thumbtack', 'color' => '#7F7F7F'],
|
||||
];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Task Category Definitions
|
||||
// Returns associative Array of Task Category Keys to Labels, Icons,
|
||||
// and Colors. Shared between Citizen Participation Portal and
|
||||
// Moderation Page.
|
||||
// ToDo: Move to Database Table.
|
||||
// ---------------------------------------------------------------------
|
||||
function get_task_categories() {
|
||||
return [
|
||||
'repair' => ['label' => 'Reparatur', 'faIcon' => 'fa-wrench', 'color' => '#C00000'],
|
||||
'social' => ['label' => 'Nachbarschaft', 'faIcon' => 'fa-people-group', 'color' => '#E65100'],
|
||||
'safety' => ['label' => 'Sicherheit', 'faIcon' => 'fa-shield-halved', 'color' => '#FFC000'],
|
||||
'greenery' => ['label' => 'Grünpflege', 'faIcon' => 'fa-leaf', 'color' => '#92D050'],
|
||||
'cleanup' => ['label' => 'Sauberkeit', 'faIcon' => 'fa-broom', 'color' => '#0070C0'],
|
||||
'other_task' => ['label' => 'Sonstiges', 'faIcon' => 'fa-clipboard-check','color' => '#7F7F7F'],
|
||||
];
|
||||
}
|
||||
@@ -130,71 +130,30 @@ $news_items = $stmt->fetchAll();
|
||||
<!-- Sidebar Tab Icons -->
|
||||
<div class="leaflet-sidebar-tabs">
|
||||
<ul role="tablist">
|
||||
<li><a href="#tab-contributions" role="tab" title="Hinweise"><i class="fa-solid fa-clipboard-list"></i></a></li>
|
||||
<li><a href="#tab-tasks" role="tab" title="Aufgaben"><i class="fa-solid fa-clipboard-check"></i></a></li>
|
||||
<li><a href="#tab-list" role="tab" title="Beiträge"><i class="fa-solid fa-list"></i></a></li>
|
||||
<li><a href="#tab-news" role="tab" title="Neuigkeiten"><i class="fa-solid fa-newspaper"></i></a></li>
|
||||
<li><a href="#tab-help" role="tab" title="Hilfe"><i class="fa-solid fa-circle-question"></i></a></li>
|
||||
<li><a href="#tab-home" role="tab"><i class="fa-solid fa-house"></i></a></li>
|
||||
<li><a href="#tab-list" role="tab"><i class="fa-solid fa-list"></i></a></li>
|
||||
<li><a href="#tab-news" role="tab"><i class="fa-solid fa-newspaper"></i></a></li>
|
||||
<li><a href="#tab-help" role="tab"><i class="fa-solid fa-circle-question"></i></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Sidebar Tab Content -->
|
||||
<div class="leaflet-sidebar-content">
|
||||
|
||||
<!-- Contributions Tab -->
|
||||
<div class="leaflet-sidebar-pane" id="tab-contributions">
|
||||
<!-- Home Tab -->
|
||||
<div class="leaflet-sidebar-pane" id="tab-home">
|
||||
<h2 class="leaflet-sidebar-header">
|
||||
Hinweise
|
||||
Start
|
||||
<span class="leaflet-sidebar-close"><i class="fa-solid fa-xmark"></i></span>
|
||||
</h2>
|
||||
<div class="sidebar-body">
|
||||
<p>Verwenden Sie die Karte, um <strong>Hinweise</strong> für die Stadtverwaltung hinzuzufügen oder bestehende Hinweise zu betrachten, bewerten und kommentieren</p>
|
||||
<p>Willkommen beim Bürgerbeteiligungsportal <strong><?= htmlspecialchars($municipality['name']) ?></strong>.</p>
|
||||
<p>Verwenden Sie die Karte, um Hinweise für die Stadtverwaltung hinzuzufügen oder bestehende Beiträge zu betrachten, zu bewerten und zu kommentieren.</p>
|
||||
|
||||
<h3>Kategorien</h3>
|
||||
<div id="category-filter">
|
||||
<!-- populated by app.js -->
|
||||
<!-- Category Filter Checkboxes — populated by app.js -->
|
||||
</div>
|
||||
|
||||
<p id="stats-container"></p>
|
||||
<!-- populated by app.js -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tasks Tab -->
|
||||
<div class="leaflet-sidebar-pane" id="tab-tasks">
|
||||
<h2 class="leaflet-sidebar-header">
|
||||
Aufgaben
|
||||
<span class="leaflet-sidebar-close"><i class="fa-solid fa-xmark"></i></span>
|
||||
</h2>
|
||||
<div class="sidebar-body">
|
||||
<p>Verwenden Sie die Karte, um <strong>Aufgaben</strong> für die Gemeinschaft hinzuzufügen oder bestehende Aufgaben zu betrachten, bewerten und kommentieren.</p>
|
||||
|
||||
<h3>Kategorien</h3>
|
||||
<div id="task-category-filter">
|
||||
<!-- populated by app.js -->
|
||||
</div>
|
||||
<p id="task-stats-container">
|
||||
<!-- populated by app.js -->
|
||||
</p>
|
||||
|
||||
<div class="task-filter-row">
|
||||
<select id="task-status-filter" class="form-input" onchange="updateTasksList()" style="margin-bottom:8px;">
|
||||
<option value="open">Offene Aufgaben</option>
|
||||
<option value="all">Alle Aufgaben</option>
|
||||
<option value="completed">Wartend auf Prüfung</option>
|
||||
<option value="verified">Erledigte Aufgaben</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Leaderboard -->
|
||||
<div id="leaderboard-container" class="leaderboard-box">
|
||||
<h3>Rangliste</h3>
|
||||
<div id="leaderboard-list"></div>
|
||||
<button class="btn btn-secondary leaderboard-more-btn" onclick="showFullLeaderboard()">
|
||||
Vollständige Rangliste
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -209,7 +168,7 @@ $news_items = $stmt->fetchAll();
|
||||
<input type="text" id="list-search-input" placeholder="Beiträge durchsuchen..." class="form-input">
|
||||
</div>
|
||||
<div id="contributions-list">
|
||||
<!-- populated by app.js -->
|
||||
<!-- Contribution Cards — populated by app.js -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -221,12 +180,15 @@ $news_items = $stmt->fetchAll();
|
||||
<span class="leaflet-sidebar-close"><i class="fa-solid fa-xmark"></i></span>
|
||||
</h2>
|
||||
<div class="sidebar-body">
|
||||
<!-- News Search -->
|
||||
<div class="list-search">
|
||||
<input type="text" id="news-search-input" placeholder="Neuigkeiten durchsuchen..." class="form-input" oninput="filterNews()">
|
||||
</div>
|
||||
|
||||
<!-- News Items Container -->
|
||||
<div id="news-list">
|
||||
<?php if (empty($news_items)): ?>
|
||||
<p style="text-align:center;color:#999;padding:20px;">Noch keine Neuigkeiten veröffentlicht.</p>
|
||||
<p class="empty-state">Noch keine Neuigkeiten veröffentlicht.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($news_items as $news): ?>
|
||||
<div class="news-item"
|
||||
@@ -256,7 +218,7 @@ $news_items = $stmt->fetchAll();
|
||||
<h3><i class="fa-solid fa-book"></i> Interaktive Anleitung</h3>
|
||||
<p>Klicken Sie unten auf Tutorial starten um Schritt für Schritt durch die Kernfunktionen der Mitmachkarte geführt zu werden.</p>
|
||||
<p>
|
||||
<button class="btn btn-primary" onclick="if(typeof restartOnboarding==='function'){sidebar.close();restartOnboarding()}" style="font-size:0.85rem;">
|
||||
<button class="btn btn-primary" onclick="if(typeof restartOnboarding==='function'){sidebar.close();restartOnboarding()}">
|
||||
<i class="fa-solid fa-route"></i> Tutorial starten
|
||||
</button>
|
||||
</p>
|
||||
@@ -273,16 +235,12 @@ $news_items = $stmt->fetchAll();
|
||||
<h3><i class="fa-solid fa-comments"></i> Kommentieren</h3>
|
||||
<p>Gerne können Sie Ihre Meinung zu bestehenden Beiträgen auch durch die Kommentarfunktion äußern.</p>
|
||||
|
||||
<h3><i class="fa-solid fa-clipboard-check"></i> Aufgaben erledigen</h3>
|
||||
<p>Klicken Sie auf eine offene Aufgabe und melden Sie die Erledigung mit einem Foto-Nachweis.</p>
|
||||
|
||||
<h3><i class="fa-solid fa-magnifying-glass"></i> Suchen</h3>
|
||||
<p>Verwenden Sie die Adresssuche rechts, um schnell den richtigen Ort auf der Mitmachkarte zu finden.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Leaflet Map -->
|
||||
@@ -316,7 +274,7 @@ $news_items = $stmt->fetchAll();
|
||||
<li>Hinweise und Verbesserungsvorschläge für die Stadtverwaltung hinzufügen</li>
|
||||
<li>Bestehende Beiträge der Bürgerschaft betrachten und bewerten</li>
|
||||
</ul>
|
||||
<p style="background:#fff3cd;padding:10px;border-radius:6px;border:1px solid #ffc107;font-size:0.85rem;color:#856404;">
|
||||
<p class="dev-notice">
|
||||
<i class="fa-solid fa-triangle-exclamation"></i> <strong>Hinweis:</strong> Demoversion - nicht in Rücksprache mit der Stadt Lohne entwickelt! Alle Beitrage, Kommentare und Personen sind frei erfunden.
|
||||
</p>
|
||||
<p>Zum Hinzufügen von Beiträgen geben Sie bitte zunächst Ihren Namen ein.</p> <div class="modal-actions">
|
||||
@@ -351,7 +309,7 @@ $news_items = $stmt->fetchAll();
|
||||
<!-- ============================================================= -->
|
||||
<div id="create-modal" class="modal-overlay" style="display:none;">
|
||||
<div class="modal-content">
|
||||
<h2><i class="fa-solid fa-plus-circle"></i> Beitrag</h2>
|
||||
<h2><i class="fa-solid fa-pencil"></i> Beitrag hinzufügen</h2>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="create-category">Kategorie</label>
|
||||
@@ -439,7 +397,6 @@ $news_items = $stmt->fetchAll();
|
||||
|
||||
// Category Definitions from Database
|
||||
const CATEGORIES = <?= json_encode(get_categories(), JSON_UNESCAPED_UNICODE) ?>;
|
||||
const TASK_CATEGORIES = <?= json_encode(get_task_categories(), JSON_UNESCAPED_UNICODE) ?>;
|
||||
|
||||
// Admin Status from PHP Session
|
||||
const IS_ADMIN = <?= (function_exists('is_admin') && is_admin()) ? 'true' : 'false' ?>;
|
||||
|
||||
185
public/js/app.js
185
public/js/app.js
@@ -88,9 +88,9 @@ basemapCartoDB.addTo(map);
|
||||
|
||||
// Layer Control
|
||||
const basemaps = {
|
||||
'<i class="fa-solid fa-map" style="color:#404040;"></i> Hintergrundkarte (farbe)': basemapOSM,
|
||||
'<i class="fa-solid fa-map" style="color:#404040;"></i> Hintergrundkarte (grau)': basemapCartoDB,
|
||||
'<i class="fa-solid fa-satellite" style="color:#404040;"></i> Satellitenbild': basemapSatellite,
|
||||
// 'Hintergrundkarte': basemapOSM,
|
||||
'Hintergrundkarte': basemapCartoDB,
|
||||
'Satellitenbild': basemapSatellite,
|
||||
};
|
||||
|
||||
const overlays = {}; // Populated later with Contribution Layers
|
||||
@@ -100,6 +100,16 @@ const layerControl = L.control.layers(basemaps, overlays, {
|
||||
collapsed: true
|
||||
}).addTo(map);
|
||||
|
||||
// Adds styled Header to Layer Control Dropdown
|
||||
var layerControlContainer = layerControl.getContainer();
|
||||
var layerList = layerControlContainer.querySelector('.leaflet-control-layers-list');
|
||||
if (layerList) {
|
||||
var header = document.createElement('div');
|
||||
header.className = 'layer-control-header';
|
||||
header.innerHTML = '<i class="fa-solid fa-layer-group"></i> Layerauswahl';
|
||||
layerList.parentNode.insertBefore(header, layerList);
|
||||
}
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// Block 4: Map Controls
|
||||
@@ -111,11 +121,11 @@ L.control.zoom({
|
||||
}).addTo(map);
|
||||
|
||||
// Scale Bar
|
||||
L.control.scale({
|
||||
position: 'bottomright',
|
||||
maxWidth: 200,
|
||||
imperial: false
|
||||
}).addTo(map);
|
||||
// L.control.scale({
|
||||
// position: 'bottomright',
|
||||
// maxWidth: 200,
|
||||
// imperial: false
|
||||
// }).addTo(map);
|
||||
|
||||
// Fullscreen Button
|
||||
L.control.fullscreen({
|
||||
@@ -220,6 +230,21 @@ sidebar = L.control.sidebar({
|
||||
position: 'left'
|
||||
}).addTo(map);
|
||||
|
||||
// Hides Map Controls on Mobile while Sidebar is open
|
||||
sidebar.on('content', function () {
|
||||
if (window.innerWidth < 769) {
|
||||
document.querySelectorAll('.leaflet-top.leaflet-right').forEach(function (el) {
|
||||
el.style.display = 'none';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
sidebar.on('closing', function () {
|
||||
document.querySelectorAll('.leaflet-top.leaflet-right').forEach(function (el) {
|
||||
el.style.display = '';
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// Block 6: Geoman Drawing Tools and CRUD Trigger
|
||||
@@ -243,6 +268,40 @@ map.pm.addControls({
|
||||
|
||||
map.pm.setLang('de');
|
||||
|
||||
// Overwrites Geoman German Translations for User-friendly Labels
|
||||
map.pm.setLang('custom', {
|
||||
tooltips: {
|
||||
placeMarker: 'Punkt setzen mit Klick',
|
||||
firstVertex: 'Ersten Punkt setzen mit Klick',
|
||||
continueLine: 'Nächsten Punkt setzen mit Klick',
|
||||
finishLine: 'Beenden mit Klick auf letzten Punkt',
|
||||
finishPoly: 'Beenden mit Klick auf ersten Punkt',
|
||||
finishRect: 'Beenden mit Klick'
|
||||
},
|
||||
actions: {
|
||||
finish: 'Beenden',
|
||||
cancel: 'Abbrechen',
|
||||
removeLastVertex: 'Letzten Punkt löschen'
|
||||
},
|
||||
buttonTitles: {
|
||||
drawMarkerButton: 'Punkt zeichnen',
|
||||
drawPolyButton: 'Fläche zeichnen',
|
||||
drawLineButton: 'Linie zeichnen',
|
||||
drawCircleButton: 'Kreis zeichnen',
|
||||
drawRectButton: 'Rechteck zeichnen',
|
||||
editButton: 'Objekte bearbeiten',
|
||||
dragButton: 'Objekte verschieben',
|
||||
cutButton: 'Objekte ausschneiden',
|
||||
deleteButton: 'Objekte löschen',
|
||||
drawCircleMarkerButton: 'Kreismarker zeichnen',
|
||||
snappingButton: 'Einrasten',
|
||||
pinningButton: 'Fixieren',
|
||||
rotateButton: 'Objekte drehen',
|
||||
drawTextButton: 'Text zeichnen'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Captures drawn Geometry and opens the Create Modal
|
||||
map.on('pm:create', function (e) {
|
||||
const geojson = e.layer.toGeoJSON().geometry;
|
||||
@@ -343,10 +402,10 @@ function loadContributions() {
|
||||
onEachFeature: bindFeaturePopup
|
||||
}).addTo(map);
|
||||
|
||||
layerControl.addOverlay(contributionsLayer, '<i class="fa-solid fa-map-pin" style="color:#C00000;"></i> Beiträge');
|
||||
layerControl.addOverlay(contributionsLayer, 'Bürgerbeiträge');
|
||||
// Update Sidebar List and Statistics
|
||||
updateContributionsList();
|
||||
updateStatistics();
|
||||
buildCategoryFilter();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -473,11 +532,25 @@ function buildPopupHtml(feature) {
|
||||
function bindFeaturePopup(feature, layer) {
|
||||
const cat = CATEGORIES[feature.properties.category] || CATEGORIES.other;
|
||||
|
||||
// Dynamic Popup — rebuilt every Time the Popup opens
|
||||
layer.bindPopup(function () { return buildPopupHtml(feature); }, { maxWidth: 320, minWidth: 240 });
|
||||
// Popup Options — Mobile narrower with Header/Footer Padding
|
||||
var mobile = window.innerWidth < 769;
|
||||
var opts = {
|
||||
maxWidth: mobile ? 280 : 320,
|
||||
minWidth: mobile ? 200 : 240,
|
||||
maxHeight: mobile ? 280 : 400,
|
||||
autoPanPaddingTopLeft: L.point(mobile ? 50 : 75, mobile ? 75 : 75),
|
||||
autoPanPaddingBottomRight: L.point(mobile ? 60 : 85, mobile ? 50 : 75),
|
||||
className: 'contribution-popup'
|
||||
};
|
||||
|
||||
// Loads Comments when Popup opens
|
||||
// Dynamic Popup — rebuilt every Time the Popup opens
|
||||
layer.bindPopup(function () { return buildPopupHtml(feature); }, opts);
|
||||
|
||||
// Closes Sidebar on Mobile and loads Comments when Popup opens
|
||||
layer.on('popupopen', function () {
|
||||
if (window.innerWidth < 769) {
|
||||
sidebar.close();
|
||||
}
|
||||
loadComments(feature.properties.contribution_id);
|
||||
});
|
||||
|
||||
@@ -766,7 +839,7 @@ function updateContributionsList() {
|
||||
|
||||
// Builds HTML
|
||||
if (filtered.length === 0) {
|
||||
container.innerHTML = '<p style="text-align:center;color:#999;padding:20px;">Keine Beiträge gefunden.</p>';
|
||||
container.innerHTML = '<p class="empty-state">Keine Beiträge gefunden.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -830,22 +903,33 @@ document.getElementById('list-search-input').addEventListener('input', function
|
||||
// Block 12: Sidebar Category Filter and Statistics
|
||||
// =====================================================================
|
||||
|
||||
// Builds Category Filter Checkboxes
|
||||
// Builds Category Filter Checkboxes with Counts
|
||||
function buildCategoryFilter() {
|
||||
const container = document.getElementById('category-filter');
|
||||
|
||||
const counts = {};
|
||||
contributionsData.forEach(function (f) {
|
||||
const cat = f.properties.category;
|
||||
counts[cat] = (counts[cat] || 0) + 1;
|
||||
});
|
||||
|
||||
const total = contributionsData.length;
|
||||
let html = '';
|
||||
|
||||
for (const key in CATEGORIES) {
|
||||
const cat = CATEGORIES[key];
|
||||
const checked = activeFilters.indexOf(key) !== -1 ? 'checked' : '';
|
||||
const count = counts[key] || 0;
|
||||
|
||||
html += '' +
|
||||
'<label style="display:flex;align-items:center;gap:8px;margin-bottom:6px;cursor:pointer;">' +
|
||||
html += '<label style="display:flex;align-items:center;gap:8px;margin-bottom:6px;cursor:pointer;font-size:0.85rem;color:var(--color-text-secondary)">' +
|
||||
'<input type="checkbox" value="' + key + '" ' + checked + ' onchange="toggleCategoryFilter(this)">' +
|
||||
'<span>' + categoryIcon(cat) + ' ' + cat.label + '</span>' +
|
||||
categoryIcon(cat) +
|
||||
'<span>' + cat.label + ' (' + count + ')</span>' +
|
||||
'</label>';
|
||||
}
|
||||
|
||||
html += '<p style="margin-top:10px;font-size:0.85rem;color:var(--color-text-secondary)"><strong>' + total + '</strong> Beiträge insgesamt</p>';
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
@@ -892,34 +976,6 @@ function toggleCategoryFilter(checkbox) {
|
||||
updateContributionsList();
|
||||
}
|
||||
|
||||
// Updates Statistics in Home Tab
|
||||
function updateStatistics() {
|
||||
const container = document.getElementById('stats-container');
|
||||
const total = contributionsData.length;
|
||||
|
||||
// Counts per Category
|
||||
// const counts = {};
|
||||
// contributionsData.forEach(function (f) {
|
||||
// const cat = f.properties.category;
|
||||
// counts[cat] = (counts[cat] || 0) + 1;
|
||||
// });
|
||||
|
||||
let html = '<p style="font-size:0.8rem;"><strong>' + total + '</strong> Hinweise insgesamt</p>';
|
||||
|
||||
// for (const key in CATEGORIES) {
|
||||
// const cat = CATEGORIES[key];
|
||||
// const count = counts[key] || 0;
|
||||
// if (count > 0) {
|
||||
// html += '<div style="display:flex;align-items:center;gap:8px;margin:4px 0;font-size:0.8rem;">' +
|
||||
// categoryIcon(cat) + ' ' +
|
||||
// cat.label + ': ' + count +
|
||||
// '</div>';
|
||||
// }
|
||||
// }
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// Block 13: Modals — Welcome, Login, Info, Privacy, Imprint
|
||||
@@ -957,6 +1013,11 @@ function submitLogin() {
|
||||
document.cookie = 'webgis_user=' + encodeURIComponent(name) + ';path=/;max-age=31536000;SameSite=Lax';
|
||||
document.getElementById('login-modal').style.display = 'none';
|
||||
|
||||
// Starts Onboarding Tour on first Login
|
||||
if (!localStorage.getItem('webgis_onboarding_done')) {
|
||||
setTimeout(function () { startTour(); }, 500);
|
||||
}
|
||||
|
||||
// Open Create Modal if Geometry is pending
|
||||
if (drawnGeometry) {
|
||||
document.getElementById('create-geom').value = JSON.stringify(drawnGeometry);
|
||||
@@ -967,6 +1028,11 @@ function submitLogin() {
|
||||
|
||||
function skipLogin() {
|
||||
document.getElementById('login-modal').style.display = 'none';
|
||||
|
||||
// Starts Onboarding Tour on first Login
|
||||
if (!localStorage.getItem('webgis_onboarding_done')) {
|
||||
setTimeout(function () { startTour(); }, 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Info Modal
|
||||
@@ -1034,7 +1100,7 @@ function escapeHtml(text) {
|
||||
|
||||
// Returns a colored Font Awesome Icon HTML String for a Category
|
||||
function categoryIcon(cat) {
|
||||
return '<i class="fa-solid ' + cat.faIcon + '" style="color:' + cat.color + ';"></i>';
|
||||
return '<i class="fa-solid ' + cat.faIcon + ' fa-fw" style="color:' + cat.color + ';"></i>';
|
||||
}
|
||||
|
||||
// Reverse Geocodes Coordinates and saves Address to Contribution via API
|
||||
@@ -1160,7 +1226,24 @@ function deleteComment(commentId, contributionId) {
|
||||
});
|
||||
}
|
||||
|
||||
// Toggles Photo Visibility in Popup
|
||||
// Pans Map if Popup behind Header
|
||||
function recenterPopup() {
|
||||
map.eachLayer(function (layer) {
|
||||
if (layer.getPopup && layer.getPopup() && layer.isPopupOpen()) {
|
||||
var popupEl = layer.getPopup().getElement();
|
||||
if (!popupEl) return;
|
||||
var padding = window.innerWidth < 769 ? 75 : 75;
|
||||
var popupTop = popupEl.getBoundingClientRect().top;
|
||||
var mapTop = document.getElementById('map').getBoundingClientRect().top;
|
||||
var diff = popupTop - mapTop - padding;
|
||||
if (diff < 0) {
|
||||
map.panBy([0, diff], { animate: true, duration: 0.3 });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Toggles Photo Visibility in Popup and updates Popup Position
|
||||
function togglePhoto(contributionId) {
|
||||
const container = document.getElementById('photo-container-' + contributionId);
|
||||
const label = document.getElementById('photo-label-' + contributionId);
|
||||
@@ -1173,9 +1256,11 @@ function togglePhoto(contributionId) {
|
||||
container.style.display = 'none';
|
||||
label.textContent = 'Foto anzeigen';
|
||||
}
|
||||
|
||||
setTimeout(recenterPopup, 150);
|
||||
}
|
||||
|
||||
// Toggles Comments Section Visibility in Popup
|
||||
// Toggles Comments Section Visibility in Popup and updates Popup Position
|
||||
function toggleComments(contributionId) {
|
||||
const section = document.getElementById('comments-section-' + contributionId);
|
||||
const toggle = document.getElementById('comments-toggle-' + contributionId);
|
||||
@@ -1192,6 +1277,8 @@ function toggleComments(contributionId) {
|
||||
toggle.classList.remove('fa-chevron-up');
|
||||
toggle.classList.add('fa-chevron-down');
|
||||
}
|
||||
|
||||
setTimeout(recenterPopup, 150);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// =====================================================================
|
||||
// WebGIS Citizen Participation Portal — Onboarding Tour
|
||||
// Guides Users through the Participation Portal
|
||||
// Guides Users through the Participation Portal.
|
||||
// On Mobile centered Overlays. On Desktop attached to User Interface.
|
||||
// =====================================================================
|
||||
|
||||
|
||||
@@ -8,76 +9,30 @@
|
||||
// Block 1: Onboarding Configuration
|
||||
// =================================================================
|
||||
|
||||
// ONBOARDING_MODE — Controls when the Tutorial is shown:
|
||||
const ONBOARDING_MODE = 'once';
|
||||
// 'once' — Shown on first Visit, stored in localStorage
|
||||
// 'session' — Shown per Browser Session, stored in sessionStorage
|
||||
// 'always' — Shows always, nothing stored
|
||||
|
||||
// Prevents double Initialization
|
||||
let onboardingStarted = false;
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Block 2: Tour Initialization
|
||||
// =================================================================
|
||||
|
||||
function initOnboardingTour() {
|
||||
|
||||
// Checks if Tutorial should be shown based on Onboarding Mode
|
||||
if (ONBOARDING_MODE === 'once' && localStorage.getItem('webgis_onboarding_done')) {
|
||||
return;
|
||||
}
|
||||
if (ONBOARDING_MODE === 'session' && sessionStorage.getItem('webgis_onboarding_done')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Waits for Welcome and Login Modals to be closed
|
||||
waitForModalsToClose(function () {
|
||||
setTimeout(startTour, 600);
|
||||
});
|
||||
// Detects Mobile Viewport
|
||||
function isMobile() {
|
||||
return window.innerWidth < 769;
|
||||
}
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Block 3: Modal Watcher — Starts Tour other Welcome and Login Modals closed
|
||||
// Block 2: Tour Definition
|
||||
// =================================================================
|
||||
|
||||
function waitForModalsToClose(callback) {
|
||||
const welcomeModal = document.getElementById('welcome-modal');
|
||||
const loginModal = document.getElementById('login-modal');
|
||||
|
||||
const checkInterval = setInterval(function () {
|
||||
const welcomeHidden = !welcomeModal || welcomeModal.style.display === 'none' || welcomeModal.style.display === '';
|
||||
const loginHidden = !loginModal || loginModal.style.display === 'none' || loginModal.style.display === '';
|
||||
|
||||
if (welcomeHidden && loginHidden) {
|
||||
clearInterval(checkInterval);
|
||||
callback();
|
||||
}
|
||||
}, 300);
|
||||
|
||||
// Safety Timeout
|
||||
setTimeout(function () {
|
||||
clearInterval(checkInterval);
|
||||
callback();
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Block 4: Tour Definition
|
||||
// =================================================================
|
||||
|
||||
function startTour() {
|
||||
function startTour(manual) {
|
||||
// Prevents double Start
|
||||
if (onboardingStarted) return;
|
||||
onboardingStarted = true;
|
||||
|
||||
const mobile = isMobile();
|
||||
|
||||
const tour = new Shepherd.Tour({
|
||||
useModalOverlay: true,
|
||||
useModalOverlay: !mobile,
|
||||
defaultStepOptions: {
|
||||
cancelIcon: { enabled: true },
|
||||
cancelIcon: { enabled: false },
|
||||
scrollTo: false,
|
||||
classes: 'onboarding-step',
|
||||
popperOptions: {
|
||||
@@ -89,46 +44,54 @@ function startTour() {
|
||||
});
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Step 1: Welcome — Skip Timer at automatic Start
|
||||
// -----------------------------------------------------------------
|
||||
// Step 1: Welcome
|
||||
// -----------------------------------------------------------------
|
||||
tour.addStep({
|
||||
id: 'welcome',
|
||||
title: '<i class="fa-solid fa-hand-wave"></i> Wilkommen bei der Mitmachkarte!',
|
||||
text: 'Dieses interaktive Tutorial zeigt Ihnen die Kernfunktionen der Mitmachkarte.' +
|
||||
'<br><br><span style="font-size:0.8rem;color:var(--color-text-secondary);">Sie können das Tutorial jederzeit durch den Hilfe-Tab der Seitenleiste wiederholen.</span>',
|
||||
buttons: [
|
||||
var welcomeButtons = [
|
||||
{
|
||||
text: 'Überspringen',
|
||||
action: tour.cancel,
|
||||
classes: 'shepherd-button-secondary'
|
||||
classes: 'shepherd-button-secondary' + (manual ? '' : ' skip-btn-locked')
|
||||
},
|
||||
{
|
||||
text: 'Los geht\'s <i class="fa-solid fa-arrow-right"></i>',
|
||||
action: tour.next,
|
||||
classes: 'shepherd-button-primary'
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
tour.addStep({
|
||||
id: 'welcome',
|
||||
title: '<i class="fa-solid fa-hand-wave"></i> Willkommen bei der Mitmachkarte!',
|
||||
text: 'Dieses <strong>interaktive Tutorial</strong> zeigt Ihnen die Kernfunktionen der Mitmachkarte.' +
|
||||
'<br><br><span style="color:var(--color-text-secondary);">Sie können das Tutorial jederzeit über den Hilfe-Tab der Seitenleiste wiederholen.</span>',
|
||||
buttons: welcomeButtons,
|
||||
when: {
|
||||
show: function () {
|
||||
if (manual) return;
|
||||
|
||||
// Locks Skip Button with Progress Bar for 5 Seconds
|
||||
var skipBtn = document.querySelector('.skip-btn-locked');
|
||||
if (!skipBtn) return;
|
||||
skipBtn.disabled = true;
|
||||
skipBtn.style.pointerEvents = 'none';
|
||||
|
||||
setTimeout(function () {
|
||||
skipBtn.disabled = false;
|
||||
skipBtn.style.pointerEvents = '';
|
||||
skipBtn.classList.remove('skip-btn-locked');
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Step 2: Drawing Tools
|
||||
// -----------------------------------------------------------------
|
||||
tour.addStep({
|
||||
var drawingStep = {
|
||||
id: 'drawing-tools',
|
||||
title: '<i class="fa-solid fa-pencil"></i> Beitrag hinzufügen',
|
||||
text: 'Verwenden Sie die <strong>Zeichenwerkzeuge</strong>, um Hinweise, Anregungen und Vorschläge auf der Mitmachkarte als Punkte, Linien oder Flächen hinzuzufügen.',
|
||||
attachTo: {
|
||||
element: '.leaflet-pm-toolbar',
|
||||
on: 'left'
|
||||
},
|
||||
beforeShowPromise: function () {
|
||||
return new Promise(function (resolve) {
|
||||
sidebar.close();
|
||||
setTimeout(resolve, 300);
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="fa-solid fa-arrow-left"></i> Zurück',
|
||||
@@ -141,20 +104,32 @@ function startTour() {
|
||||
classes: 'shepherd-button-primary'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
if (mobile) {
|
||||
drawingStep.text = 'Verwenden Sie die <strong>Zeichenwerkzeuge</strong> ' +
|
||||
'<i class="fa-solid fa-location-dot"></i> ' +
|
||||
'rechts, um Hinweise als Punkte, Linien oder Flächen hinzuzufügen.';
|
||||
} else {
|
||||
drawingStep.text = 'Verwenden Sie die <strong>Zeichenwerkzeuge</strong>, um Hinweise, Anregungen und Vorschläge auf der Mitmachkarte als Punkte, Linien oder Flächen hinzuzufügen.';
|
||||
drawingStep.attachTo = { element: '.leaflet-pm-toolbar', on: 'left' };
|
||||
drawingStep.beforeShowPromise = function () {
|
||||
return new Promise(function (resolve) {
|
||||
sidebar.close();
|
||||
setTimeout(resolve, 300);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
tour.addStep(drawingStep);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Step 3: Address Search
|
||||
// -----------------------------------------------------------------
|
||||
tour.addStep({
|
||||
var searchStep = {
|
||||
id: 'address-search',
|
||||
title: '<i class="fa-solid fa-magnifying-glass"></i> Adresssuche',
|
||||
text: 'Verwenden Sie die <strong>Adresssuche</strong>, um schnell den richtigen Ort auf der Mitmachkarte zu finden.',
|
||||
attachTo: {
|
||||
element: '.leaflet-control-geocoder',
|
||||
on: 'left'
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="fa-solid fa-arrow-left"></i> Zurück',
|
||||
@@ -167,20 +142,25 @@ function startTour() {
|
||||
classes: 'shepherd-button-primary'
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
if (mobile) {
|
||||
searchStep.text = 'Verwenden Sie die <strong>Adresssuche</strong> ' +
|
||||
'<i class="fa-solid fa-magnifying-glass"></i> rechts, um schnell den richtigen Ort auf der Mitmachkarte zu finden.';
|
||||
} else {
|
||||
searchStep.text = 'Verwenden Sie die <strong>Adresssuche</strong>, um schnell den richtigen Ort auf der Mitmachkarte zu finden.';
|
||||
searchStep.attachTo = { element: '.leaflet-control-geocoder', on: 'left' };
|
||||
}
|
||||
|
||||
tour.addStep(searchStep);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Step 4: Layer Control
|
||||
// -----------------------------------------------------------------
|
||||
tour.addStep({
|
||||
var layerStep = {
|
||||
id: 'layer-control',
|
||||
title: '<i class="fa-solid fa-layer-group"></i> Kartenansicht',
|
||||
text: 'Wechseln Sie zwischen verschiedenen <strong>Hintergrundkarten</strong> und <strong>Satellitenbildern</strong>.',
|
||||
attachTo: {
|
||||
element: '.leaflet-control-layers',
|
||||
on: 'left'
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="fa-solid fa-arrow-left"></i> Zurück',
|
||||
@@ -193,26 +173,25 @@ function startTour() {
|
||||
classes: 'shepherd-button-primary'
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
if (mobile) {
|
||||
layerStep.text = 'Wechseln Sie über das <strong>Layer-Symbol</strong> ' +
|
||||
'<i class="fa-solid fa-layer-group"></i> oben rechts zwischen verschiedenen Hintergrundkarten und Satellitenbildern.';
|
||||
} else {
|
||||
layerStep.text = 'Wechseln Sie zwischen verschiedenen <strong>Hintergrundkarten</strong> und <strong>Satellitenbildern</strong>.';
|
||||
layerStep.attachTo = { element: '.leaflet-control-layers', on: 'left' };
|
||||
}
|
||||
|
||||
tour.addStep(layerStep);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Step 5: Sidebar
|
||||
// -----------------------------------------------------------------
|
||||
tour.addStep({
|
||||
var sidebarStep = {
|
||||
id: 'sidebar',
|
||||
title: '<i class="fa-solid fa-bars"></i> Seitenleiste',
|
||||
text: 'In der Seitenleiste finden Sie <strong>Hilfestellungen</strong>, <strong>Listenansichten</strong> und <strong>Neuigkeiten</strong>.',
|
||||
attachTo: {
|
||||
element: '#sidebar',
|
||||
on: 'right'
|
||||
},
|
||||
beforeShowPromise: function () {
|
||||
return new Promise(function (resolve) {
|
||||
sidebar.open('tab-help');
|
||||
setTimeout(resolve, 400);
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="fa-solid fa-arrow-left"></i> Zurück',
|
||||
@@ -220,58 +199,106 @@ function startTour() {
|
||||
classes: 'shepherd-button-secondary'
|
||||
},
|
||||
{
|
||||
text: 'Tutorial abschließen <i class="fa-solid fa-check"></i>',
|
||||
text: 'Abschließen <i class="fa-solid fa-check"></i>',
|
||||
action: tour.next,
|
||||
classes: 'shepherd-button-primary'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
if (mobile) {
|
||||
sidebarStep.text = 'In der <strong>Seitenleiste</strong> ' +
|
||||
'<i class="fa-solid fa-house"></i> ' +
|
||||
'links finden Sie Hilfestellungen, Listenansichten und Neuigkeiten.';
|
||||
} else {
|
||||
sidebarStep.text = 'In der <strong>Seitenleiste</strong> finden Sie Hilfestellungen, Listenansichten und Neuigkeiten.';
|
||||
sidebarStep.attachTo = { element: '#sidebar', on: 'right' };
|
||||
sidebarStep.beforeShowPromise = function () {
|
||||
return new Promise(function (resolve) {
|
||||
sidebar.open('tab-help');
|
||||
setTimeout(resolve, 400);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
tour.addStep(sidebarStep);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Completion and Cancellation
|
||||
// Completion and Cancellation — shows Drawing Arrow
|
||||
// -----------------------------------------------------------------
|
||||
tour.on('complete', function () {
|
||||
markOnboardingDone();
|
||||
function onTourEnd() {
|
||||
onboardingStarted = false;
|
||||
});
|
||||
if (mobile) sidebar.close();
|
||||
|
||||
tour.on('cancel', function () {
|
||||
markOnboardingDone();
|
||||
onboardingStarted = false;
|
||||
});
|
||||
// Shows Arrow Hint
|
||||
if (!localStorage.getItem('webgis_onboarding_done')) {
|
||||
localStorage.setItem('webgis_onboarding_done', 'true');
|
||||
showDrawingArrow();
|
||||
}
|
||||
}
|
||||
|
||||
tour.on('complete', onTourEnd);
|
||||
tour.on('cancel', onTourEnd);
|
||||
|
||||
tour.start();
|
||||
}
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Marks Onboarding as completed
|
||||
// Drawing Arrow — Points to Geoman Toolbar after Tour
|
||||
// =================================================================
|
||||
|
||||
function markOnboardingDone() {
|
||||
if (ONBOARDING_MODE === 'once') {
|
||||
localStorage.setItem('webgis_onboarding_done', 'true');
|
||||
} else if (ONBOARDING_MODE === 'session') {
|
||||
sessionStorage.setItem('webgis_onboarding_done', 'true');
|
||||
function showDrawingArrow() {
|
||||
var hint = document.createElement('div');
|
||||
hint.id = 'drawing-hint-arrow';
|
||||
hint.innerHTML = '<span class="drawing-hint-label">' +
|
||||
'<i class="fa-solid fa-pencil"></i> Beitrag hinzufügen' +
|
||||
'</span>' +
|
||||
'<span class="drawing-hint-chevrons">' +
|
||||
'<i class="fa-solid fa-chevron-right"></i>' +
|
||||
'<i class="fa-solid fa-chevron-right"></i>' +
|
||||
'</span>';
|
||||
document.body.appendChild(hint);
|
||||
|
||||
// Positions Hint centered on Geoman Toolbar
|
||||
function positionHint() {
|
||||
var toolbar = document.querySelector('.leaflet-pm-toolbar');
|
||||
if (!toolbar) { removeDrawingArrow(); return; }
|
||||
|
||||
var rect = toolbar.getBoundingClientRect();
|
||||
var hintHeight = hint.offsetHeight || 32;
|
||||
hint.style.top = (rect.top + (rect.height / 2) - (hintHeight / 2)) + 'px';
|
||||
hint.style.right = (window.innerWidth - rect.left + 10) + 'px';
|
||||
}
|
||||
|
||||
positionHint();
|
||||
window.addEventListener('resize', positionHint);
|
||||
|
||||
var timeout = setTimeout(removeDrawingArrow, 60000);
|
||||
|
||||
map.on('pm:globaldrawmodetoggled', function onDraw() {
|
||||
clearTimeout(timeout);
|
||||
removeDrawingArrow();
|
||||
map.off('pm:globaldrawmodetoggled', onDraw);
|
||||
window.removeEventListener('resize', positionHint);
|
||||
});
|
||||
}
|
||||
|
||||
function removeDrawingArrow() {
|
||||
var arrow = document.getElementById('drawing-hint-arrow');
|
||||
if (arrow) {
|
||||
arrow.classList.add('fade-out');
|
||||
setTimeout(function () { arrow.remove(); }, 300);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Manual Tour Restart
|
||||
// Manual Tour Restart (from Info Modal or Help Tab)
|
||||
// =================================================================
|
||||
|
||||
function restartOnboarding() {
|
||||
localStorage.removeItem('webgis_onboarding_done');
|
||||
sessionStorage.removeItem('webgis_onboarding_done');
|
||||
onboardingStarted = false;
|
||||
startTour();
|
||||
startTour(true);
|
||||
}
|
||||
|
||||
|
||||
// =================================================================
|
||||
// Auto-Start on Page Load
|
||||
// =================================================================
|
||||
|
||||
initOnboardingTour();
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user