Skip to content

Commit c489e1e

Browse files
committed
* implementing Sharing Permissions - STEP 14.2 - added another type of timestamp for permissions and a parameter for EmulateForceRefresh
* obtaining last timestamps now has notes/projects/permissions * reworked the automatic refresh routine on the JS side to check conditions over all 3 types
1 parent 7a4a35b commit c489e1e

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

Assets/js/notes.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -1715,22 +1715,29 @@ static CheckAndTriggerRefresh(lastModifiedTimestamp) {
17151715
//console.log(lastModifiedTimestamp);
17161716
//console.log(lastRefreshedTimestamp);
17171717

1718-
if (is_project && !is_sharing && lastRefreshedTimestamp < lastModifiedTimestamp.notes) {
1719-
_TodoNotes_Requests_.RefreshNotes(project_id, user_id);
1720-
}
1721-
if (!is_sharing && lastRefreshedTimestamp < lastModifiedTimestamp.projects) {
1722-
const is_custom = $("#refProjectId").attr('data-is-custom');
1723-
const is_global = $("#refProjectId").attr('data-is-global');
1724-
const is_owner = $("#refProjectId").attr('data-is-owner');
1725-
if (is_custom && !is_global && !is_owner) {
1718+
if (is_sharing) {
1719+
// Sharing permissions view
1720+
if (!is_project && (lastRefreshedTimestamp < lastModifiedTimestamp.projects || lastRefreshedTimestamp < lastModifiedTimestamp.permissions)) {
1721+
//alert('RefreshAll sharing');
17261722
_TodoNotes_Requests_.RefreshAll(project_id, user_id, is_sharing);
1723+
}
1724+
} else {
1725+
// Note list view
1726+
if (lastRefreshedTimestamp < lastModifiedTimestamp.permissions) {
1727+
//alert('RefreshAll notes');
1728+
_TodoNotes_Requests_.RefreshAll(project_id, user_id, is_sharing);
17271729
} else {
1728-
_TodoNotes_Requests_.RefreshTabs(user_id);
1730+
if (is_project && lastRefreshedTimestamp < lastModifiedTimestamp.notes) {
1731+
//alert('RefreshNotes');
1732+
_TodoNotes_Requests_.RefreshNotes(project_id, user_id);
1733+
}
1734+
if (lastRefreshedTimestamp < lastModifiedTimestamp.projects) {
1735+
//alert('RefreshTabs');
1736+
_TodoNotes_Requests_.RefreshTabs(user_id);
1737+
}
17291738
}
17301739
}
1731-
if (is_sharing && !is_project && lastRefreshedTimestamp < lastModifiedTimestamp.max) {
1732-
_TodoNotes_Requests_.RefreshAll(project_id, user_id, is_sharing);
1733-
}
1740+
17341741
if (lastRefreshedTimestamp < lastModifiedTimestamp.max) {
17351742
$("#refProjectId").attr('data-timestamp', lastModifiedTimestamp.max);
17361743
}

Controller/TodoNotesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public function SetSharingPermission()
745745
} else {
746746
// All other cases Global/Private+Owner/Regular should be valid for sharing !
747747
$this->todoNotesModel->SetSharingPermission($project_id, $user_id, $shared_user_id, $shared_permission);
748-
$timestamp = $this->todoNotesModel->EmulateForceRefresh();
748+
$timestamp = $this->todoNotesModel->EmulateForceRefresh('permissions');
749749
$this->flash->success(t('TodoNotes__DASHBOARD_OPERATION_SHARING_NOTE_LIST_SUCCESS'));
750750
}
751751

Model/TodoNotesModel.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public function UpdateCustomNoteListsPositions($user_id, $customListsPositions)
991991
}
992992

993993
// Emulate a global force refresh by updating a modified/archived timestamp to the special `zero` entry
994-
public function EmulateForceRefresh()
994+
public function EmulateForceRefresh($type = 'projects')
995995
{
996996
// Get current unixtime
997997
$timestamp = time();
@@ -1001,13 +1001,13 @@ public function EmulateForceRefresh()
10011001
->eq('user_id', 0)
10021002
->eq('position', 0)
10031003
->eq('is_active', -1)
1004-
->update(array('date_modified' => $timestamp));
1004+
->update(array('category' => $type, 'date_modified' => $timestamp));
10051005

10061006
$this->db->table(self::TABLE_NOTES_ARCHIVE_ENTRIES)
10071007
->eq('project_id', 0)
10081008
->eq('user_id', 0)
10091009
->eq('date_modified', -1)
1010-
->update(array('date_archived' => $timestamp));
1010+
->update(array('category' => $type, 'date_archived' => $timestamp));
10111011

10121012
return $timestamp;
10131013
}
@@ -1031,21 +1031,28 @@ public function GetLastModifiedTimestamp($project_id, $user_id)
10311031
}
10321032

10331033
$forceRefresh = $this->db->table(self::TABLE_NOTES_ENTRIES)
1034-
->columns('date_modified')
1034+
->columns('date_modified', 'category')
10351035
->eq('project_id', 0)
10361036
->eq('user_id', 0)
10371037
->eq('position', 0)
10381038
->eq('is_active', -1)
10391039
->findOne();
10401040

10411041
$timestampProjects = 0;
1042-
if ($forceRefresh && count($forceRefresh) == 1) {
1043-
$timestampProjects = $forceRefresh['date_modified'];
1042+
$timestampPermissions = 0;
1043+
if ($forceRefresh && count($forceRefresh) == 2) {
1044+
if ($forceRefresh['category'] == "projects") {
1045+
$timestampProjects = $forceRefresh['date_modified'];
1046+
}
1047+
if ($forceRefresh['category'] == 'permissions') {
1048+
$timestampPermissions = $forceRefresh['date_modified'];
1049+
}
10441050
}
10451051

10461052
return array(
10471053
'notes' => $timestampNotes,
10481054
'projects' => $timestampProjects,
1055+
'permissions' => $timestampPermissions,
10491056
'max' => max($timestampNotes, $timestampProjects),
10501057
);
10511058
}
@@ -1262,20 +1269,27 @@ public function GetLastArchivedTimestamp($project_id, $user_id)
12621269
}
12631270

12641271
$forceRefresh = $this->db->table(self::TABLE_NOTES_ARCHIVE_ENTRIES)
1265-
->columns('date_archived')
1272+
->columns('date_archived', 'category')
12661273
->eq('project_id', 0)
12671274
->eq('user_id', 0)
12681275
->eq('date_modified', -1)
12691276
->findOne();
12701277

12711278
$timestampProjects = 0;
1272-
if ($forceRefresh && count($forceRefresh) == 1) {
1273-
$timestampProjects = $forceRefresh['date_archived'];
1279+
$timestampPermissions = 0;
1280+
if ($forceRefresh && count($forceRefresh) == 2) {
1281+
if ($forceRefresh['category'] == 'projects') {
1282+
$timestampProjects = $forceRefresh['date_archived'];
1283+
}
1284+
if ($forceRefresh['category'] == 'permissions') {
1285+
$timestampPermissions = $forceRefresh['date_archived'];
1286+
}
12741287
}
12751288

12761289
return array(
12771290
'notes' => $timestampNotes,
12781291
'projects' => $timestampProjects,
1292+
'permissions' => $timestampPermissions,
12791293
'max' => max($timestampNotes, $timestampProjects),
12801294
);
12811295
}

Template/project/data.php

-3
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,6 @@
11991199
print '<div class="hideMe" id="refProjectId"';
12001200
print ' data-user="' . $user_id . '"';
12011201
print ' data-project="' . $project_id . '"';
1202-
print ' data-is-custom="' . $projectAccess['is_custom'] . '"';
1203-
print ' data-is-global="' . $projectAccess['is_global'] . '"';
1204-
print ' data-is-owner="' . $projectAccess['is_owner'] . '"';
12051202
print ' data-readonly="' . $isReadOnlyMode . '"';
12061203
print ' data-note="' . (isset($note_id) ? $note_id : 0) . '"';
12071204
print ' data-timestamp="' . $current_time . '"';

0 commit comments

Comments
 (0)