diff --git a/models/project.js b/models/project.js index 7d33f945..b054afde 100644 --- a/models/project.js +++ b/models/project.js @@ -664,6 +664,37 @@ function getProjectsForAccount(accountId) { return projectList; } +/** + * Check if any active projects exist (optionally filtered by account) + * @param {number} [accountId] - Optional account ID. If omitted or < 0, checks across all accounts. + * @returns {boolean} true if at least one active project exists, false otherwise. + */ +function hasProjects(accountId) { + var exists = false; + + try { + var db = Sql.LocalStorage.openDatabaseSync(DBCommon.NAME, DBCommon.VERSION, DBCommon.DISPLAY_NAME, DBCommon.SIZE); + + db.transaction(function (tx) { + var query = "SELECT id FROM project_project_app WHERE (status IS NULL OR status != 'deleted')"; + var params = []; + + if (accountId !== undefined && accountId !== null && accountId >= 0) { + query += " AND account_id = ?"; + params.push(accountId); + } + query += " LIMIT 1"; + + var result = tx.executeSql(query, params); + exists = result.rows.length > 0; + }); + } catch (e) { + Logger.error("Project", "hasProjects failed:", e); + } + + return exists; +} + /** * Paginated version of getProjectsForAccount for infinite scroll. * diff --git a/qml/features/dashboard/pages/Dashboard.qml b/qml/features/dashboard/pages/Dashboard.qml index f567f7dc..584f9849 100644 --- a/qml/features/dashboard/pages/Dashboard.qml +++ b/qml/features/dashboard/pages/Dashboard.qml @@ -28,6 +28,7 @@ import QtQuick.Controls 2.2 as Controls import Lomiri.Components.Popups 1.3 import QtQuick.Layouts 1.3 import "../../../../models/timesheet.js" as TimesheetModel +import "../../../../models/project.js" as Project import "../../../../models/accounts.js" as Account import "../../../../models/global.js" as Global import "../../../components" @@ -276,6 +277,13 @@ Page { ] onMenuItemSelected: { if (index === 0) { + var targetAccountId = (typeof accountPicker !== "undefined" && accountPicker && accountPicker.selectedAccountId !== undefined) + ? accountPicker.selectedAccountId + : -1; + if (!Project.hasProjects(targetAccountId)) { + notifPopup.open(i18n.dtr("ubtms", "Notice"), i18n.dtr("ubtms", "No projects found. Please create a project first."), "warning"); + return; + } apLayout.addPageToNextColumn(mainPage, Qt.resolvedUrl("../../tasks/pages/Tasks.qml"), { "recordid": 0, "isReadOnly": false diff --git a/qml/features/tasks/pages/MyTasksPage.qml b/qml/features/tasks/pages/MyTasksPage.qml index 53332c64..757ef395 100644 --- a/qml/features/tasks/pages/MyTasksPage.qml +++ b/qml/features/tasks/pages/MyTasksPage.qml @@ -26,6 +26,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import Lomiri.Components 1.3 import "../../../../models/timesheet.js" as Timesheet +import "../../../../models/project.js" as Project import "../../../../models/task.js" as Task import "../../../../models/accounts.js" as Account import "../../../../models/global.js" as Global @@ -435,6 +436,13 @@ Page { onMenuItemSelected: { if (index === 0) { + var targetAccountId = (typeof accountPicker !== "undefined" && accountPicker && accountPicker.selectedAccountId !== undefined) + ? accountPicker.selectedAccountId + : -1; + if (!Project.hasProjects(targetAccountId)) { + notifPopup.open(i18n.dtr("ubtms", "Notice"), i18n.dtr("ubtms", "No projects found. Please create a project first."), "warning"); + return; + } apLayout.addPageToNextColumn(myTasksPage, Qt.resolvedUrl("Tasks.qml"), { "recordid": 0, "isReadOnly": false diff --git a/qml/features/tasks/pages/Task_Page.qml b/qml/features/tasks/pages/Task_Page.qml index 0be7c344..f9f01ecd 100644 --- a/qml/features/tasks/pages/Task_Page.qml +++ b/qml/features/tasks/pages/Task_Page.qml @@ -27,7 +27,6 @@ import QtQuick.Controls 2.2 import Lomiri.Components 1.3 import QtQuick.Window 2.2 import QtQml.Models 2.3 -import "../../../../models/timesheet.js" as Model import "../../../../models/timesheet.js" as Timesheet import "../../../../models/project.js" as Project import "../../../../models/task.js" as Task @@ -433,6 +432,13 @@ Page { ] onMenuItemSelected: { if (index === 0) { + var targetAccountId = (typeof accountPicker !== "undefined" && accountPicker && accountPicker.selectedAccountId !== undefined) + ? accountPicker.selectedAccountId + : -1; + if (!Project.hasProjects(targetAccountId)) { + notifPopup.open(i18n.dtr("ubtms", "Notice"), i18n.dtr("ubtms", "No projects found. Please create a project first."), "warning"); + return; + } apLayout.addPageToNextColumn(task, Qt.resolvedUrl("Tasks.qml"), { "recordid": 0, "isReadOnly": false