Skip to content

Commit b4bdbe4

Browse files
committed
prefer taskapp timestamps
1 parent e25d751 commit b4bdbe4

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

static/js/task.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,18 +1124,40 @@ $(document).ready(function(){
11241124
$(document).ready(function(){
11251125
$(document).on('click', '#importButton', function(){
11261126
var input = document.getElementById('importInput');
1127+
var importButton = document.getElementById('importButton');
1128+
var overwriteTempleTimestamps = document.getElementById('overwriteTempleTimestamps');
11271129
var username = input.value;
11281130
var importConent = document.getElementById('importContent');
11291131

1132+
if (importButton) {
1133+
importButton.disabled = true;
1134+
importButton.textContent = 'Importing...';
1135+
}
1136+
1137+
var preferTaskappTimestamps = true;
1138+
if (overwriteTempleTimestamps) {
1139+
preferTaskappTimestamps = overwriteTempleTimestamps.checked;
1140+
}
1141+
11301142
req = $.ajax({
11311143
url : '/collectionlog_import/',
11321144
type : 'POST',
1133-
data : {username : username}
1145+
data : {
1146+
username : username,
1147+
overwriteTempleTimestamps: preferTaskappTimestamps,
1148+
}
11341149
});
11351150

11361151
req.done(function(data) {
11371152
$(importConent).html(data)
11381153
});
1154+
1155+
req.fail(function() {
1156+
if (importButton) {
1157+
importButton.disabled = false;
1158+
importButton.textContent = 'Import';
1159+
}
1160+
});
11391161
});
11401162
});
11411163

task_database.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ def manual_revert_tasks(username, tier, task_id):
662662

663663

664664
def update_imported_tasks(username: str, all_tasks: list, username2: str,
665-
recorded_item_ids_by_tier: dict | None = None):
665+
recorded_item_ids_by_tier: dict | None = None,
666+
overwrite_temple_timestamps: bool = True):
666667
coll = mydb['taskLists']
667668
include = {'easy', 'medium', 'hard', 'elite'}
668669
tasks_to_check = []
@@ -761,6 +762,40 @@ def sanitize_recorded_map(value):
761762
existing_recorded_hard = sanitize_recorded_map(diaries['tiers']['hard'].get('recordedItemIdsByTask', {}))
762763
existing_recorded_elite = sanitize_recorded_map(diaries['tiers']['elite'].get('recordedItemIdsByTask', {}))
763764

765+
def existing_completed_date_map(completed_tasks):
766+
output = {}
767+
for entry in completed_tasks:
768+
task_id = entry.get('id')
769+
if not task_id:
770+
continue
771+
completed_date = entry.get('completedDate')
772+
if completed_date is None:
773+
continue
774+
normalized_date = __datetime_to_iso(completed_date)
775+
if normalized_date:
776+
output[task_id] = normalized_date
777+
return output
778+
779+
existing_completed_dates_easy = existing_completed_date_map(diaries['tiers']['easy'].get('completedTasks', []))
780+
existing_completed_dates_medium = existing_completed_date_map(diaries['tiers']['medium'].get('completedTasks', []))
781+
existing_completed_dates_hard = existing_completed_date_map(diaries['tiers']['hard'].get('completedTasks', []))
782+
existing_completed_dates_elite = existing_completed_date_map(diaries['tiers']['elite'].get('completedTasks', []))
783+
784+
if overwrite_temple_timestamps:
785+
tier_existing_dates = [
786+
existing_completed_dates_easy,
787+
existing_completed_dates_medium,
788+
existing_completed_dates_hard,
789+
existing_completed_dates_elite,
790+
]
791+
for tier_tasks, tier_date_map in zip(all_tasks, tier_existing_dates):
792+
for imported_task in tier_tasks:
793+
task_id = imported_task.get('id')
794+
if not task_id:
795+
continue
796+
if task_id in tier_date_map:
797+
imported_task['completedDate'] = tier_date_map[task_id]
798+
764799
imported_recorded_easy = sanitize_recorded_map(recorded_item_ids_by_tier.get('easy', {}))
765800
imported_recorded_medium = sanitize_recorded_map(recorded_item_ids_by_tier.get('medium', {}))
766801
imported_recorded_hard = sanitize_recorded_map(recorded_item_ids_by_tier.get('hard', {}))

taskapp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def collection_log_check():
567567
def collection_log_import():
568568
form_data = request.form
569569
rs_username = form_data['username']
570+
overwrite_temple_timestamps_raw = form_data.get('overwriteTempleTimestamps', 'true')
571+
overwrite_temple_timestamps = str(overwrite_temple_timestamps_raw).lower() == 'true'
570572
easy_import_result = check_logs(rs_username, tasklists.list_for_tier('easy'), 'import-recorded')
571573
medium_import_result = check_logs(rs_username, tasklists.list_for_tier('medium'), 'import-recorded')
572574
hard_import_result = check_logs(rs_username, tasklists.list_for_tier('hard'), 'import-recorded')
@@ -587,6 +589,7 @@ def collection_log_import():
587589
all_tasks,
588590
form_data['username'],
589591
recorded_item_ids_by_tier,
592+
overwrite_temple_timestamps,
590593
)
591594

592595
return render_template('collection_log_import.html',

templates/temple-sync.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ <h3>Import from TempleOSRS</h3>
3838
</ol>
3939

4040
<p class="complete">Once you have ensured your TempleOSRS data is updated/sync'd, enter your Runescape Username and click Import.</p>
41+
<div class="import-input-section" title="When checked TaskApp timestamps will be preferred over TempleOSRS timestamps.">
42+
<label class="complete" for="overwriteTempleTimestamps" style="display:flex; align-items:center; gap:8px; justify-content:center;">
43+
<input type="checkbox" id="overwriteTempleTimestamps" checked>
44+
Overwrite Temple timestamps
45+
</label>
46+
</div>
4147
<div class="import-input-section">
4248
<input class="rc-input" type="text" name="inputText" id="importInput" placeholder="RSN">
4349
<button id="importButton" class="rsText button-complete button-green">Import</button>

0 commit comments

Comments
 (0)