Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions qml/features/dashboard/pages/Dashboard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions qml/features/tasks/pages/MyTasksPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion qml/features/tasks/pages/Task_Page.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading