Skip to content

Commit

Permalink
Revert "💻 Remove developer mode" (#6050)
Browse files Browse the repository at this point in the history
This reverts commit b14e163.

Unfixes #5987

As discussed with @MarleenGilsing during the last contributors meeting, the removal of this feature will be put behind a flag and released together with other changes and new features.
  • Loading branch information
boryanagoncharenko authored Dec 18, 2024
1 parent 21302d6 commit a7314c1
Show file tree
Hide file tree
Showing 70 changed files with 665 additions and 426 deletions.
17 changes: 17 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,10 @@ def hour_of_code(level, program_id=None):

adventures_map = {a.short_name: a for a in adventures}

enforce_developers_mode = False
if 'other_settings' in customizations and 'developers_mode' in customizations['other_settings']:
enforce_developers_mode = True

hide_cheatsheet = False
if 'other_settings' in customizations and 'hide_cheatsheet' in customizations['other_settings']:
hide_cheatsheet = True
Expand Down Expand Up @@ -1355,6 +1359,7 @@ def hour_of_code(level, program_id=None):
HOC_tracking_pixel=True,
customizations=customizations,
hide_cheatsheet=hide_cheatsheet,
enforce_developers_mode=enforce_developers_mode,
loaded_program=loaded_program,
adventures=adventures,
initial_tab=initial_tab,
Expand All @@ -1377,6 +1382,7 @@ def hour_of_code(level, program_id=None):
adventures=adventures,
initial_tab=initial_tab,
current_user_name=current_user()['username'],
enforce_developers_mode=enforce_developers_mode,
))


Expand Down Expand Up @@ -1529,6 +1535,9 @@ def index(level, program_id):

adventures_map = {a.short_name: a for a in adventures}

enforce_developers_mode = False
if 'other_settings' in customizations and 'developers_mode' in customizations['other_settings']:
enforce_developers_mode = True
hide_cheatsheet = False
if 'other_settings' in customizations and 'hide_cheatsheet' in customizations['other_settings']:
hide_cheatsheet = True
Expand Down Expand Up @@ -1584,6 +1593,7 @@ def index(level, program_id):
next_level=next_level,
customizations=customizations,
hide_cheatsheet=hide_cheatsheet,
enforce_developers_mode=enforce_developers_mode,
loaded_program=loaded_program,
adventures=adventures,
initial_tab=initial_tab,
Expand All @@ -1603,6 +1613,7 @@ def index(level, program_id):
adventures_for_index=adventures_for_index,
# See initialize.ts
javascript_page_options=dict(
enforce_developers_mode=enforce_developers_mode,
page='code', # change to tryit
level=level_number,
lang=g.lang,
Expand Down Expand Up @@ -1755,6 +1766,9 @@ def tryit(level, program_id):

adventures_map = {a.short_name: a for a in adventures}

enforce_developers_mode = False
if 'other_settings' in customizations and 'developers_mode' in customizations['other_settings']:
enforce_developers_mode = True
hide_cheatsheet = False
if 'other_settings' in customizations and 'hide_cheatsheet' in customizations['other_settings']:
hide_cheatsheet = True
Expand Down Expand Up @@ -1810,6 +1824,7 @@ def tryit(level, program_id):
next_level=next_level,
customizations=customizations,
hide_cheatsheet=hide_cheatsheet,
enforce_developers_mode=enforce_developers_mode,
loaded_program=loaded_program,
adventures=adventures,
initial_tab=initial_tab,
Expand All @@ -1829,6 +1844,7 @@ def tryit(level, program_id):
adventures_for_index=adventures_for_index,
# See initialize.ts
javascript_page_options=dict(
enforce_developers_mode=enforce_developers_mode,
page='tryit',
level=level_number,
lang=g.lang,
Expand Down Expand Up @@ -2068,6 +2084,7 @@ def get_specific_adventure(name, level, mode):
max_level=hedy.HEDY_MAX_LEVEL,
customizations=customizations,
hide_cheatsheet=None,
enforce_developers_mode=None,
teacher_adventures=[],
adventures=adventures,
initial_tab=initial_tab,
Expand Down
6 changes: 6 additions & 0 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ msgstr ""
msgid "destroy_profile"
msgstr ""

msgid "developers_mode"
msgstr ""

msgid "directly_available"
msgstr ""

Expand Down Expand Up @@ -965,6 +968,9 @@ msgstr ""
msgid "male"
msgstr ""

msgid "mandatory_mode"
msgstr ""

msgid "more_info"
msgstr ""

Expand Down
86 changes: 53 additions & 33 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export interface InitializeCodePageOptions {
readonly initial_tab: string;
readonly current_user_name?: string;
readonly suppress_save_and_load_for_slides?: boolean;
readonly enforce_developers_mode?: boolean;
}

/**
Expand Down Expand Up @@ -265,7 +266,7 @@ export function initializeCodePage(options: InitializeCodePageOptions) {
adventure.save_info = 'local-storage';
}
}
reconfigurePageBasedOnTab();
reconfigurePageBasedOnTab(options.enforce_developers_mode);
checkNow();
theLocalSaveWarning.switchTab();
});
Expand Down Expand Up @@ -1441,6 +1442,40 @@ function createModal(level:number ){
modal.repair(editor, 0, title);
}

export function setDevelopersMode(event='click', enforceDevMode: boolean) {
let enable: boolean = false;
switch (event) {
case 'load':
const lastSelection = window.localStorage.getItem('developer_mode') === 'true';
enable = enforceDevMode || lastSelection;
$('#developers_toggle').prop('checked', enable);
break;

case 'click':
// Toggled
enable = $('#developers_toggle').prop('checked');
break;
}
if (!enforceDevMode) window.localStorage.setItem('developer_mode', `${enable}`)
toggleDevelopersMode(!!enforceDevMode)
}

function toggleDevelopersMode(enforceDevMode: boolean) {
const enable = window.localStorage.getItem('developer_mode') === 'true' || enforceDevMode;
// DevMode hides the tabs and makes resizable elements track the appropriate size.
// (Driving from HTML attributes is more flexible on what gets resized, and avoids duplicating
// size literals between HTML and JavaScript).
$('#adventures_tab').toggle(!enable || currentTab === 'quiz' || currentTab === 'parsons');
// this is for the new design, it needs to be removed once we ship it
$('#adventures').toggle(!enable || currentTab === 'quiz' || currentTab === 'parsons');
// Parsons dont need a fixed height
if (currentTab === 'parsons') return
$('[data-devmodeheight]').each((_, el) => {
const heights = $(el).data('devmodeheight').split(',') as string[];
$(el).css('height', heights[enable ? 1 : 0]);
});
}

export function saveForTeacherTable(table: string) {
let show_table = window.localStorage.getItem(table);
window.localStorage.setItem(table, (show_table !== 'true').toString())
Expand Down Expand Up @@ -1674,16 +1709,16 @@ function resetWindow() {
* Update page element visibilities/states based on the state of the current tab
*/
function updatePageElements() {
const isParsonsTab = currentTab === 'parsons'
const isCodeTab = !(currentTab === 'quiz' || isParsonsTab);
const isCodeTab = !(currentTab === 'quiz' || currentTab === 'parsons');

// .toggle(bool) sets visibility based on the boolean

$('#adventures_tab').toggle(true);
// this is for the new design, it needs to be removed once we ship it
$('#adventures').toggle(true);
// Explanation area is visible for non-code tabs, or when we are NOT in developer's mode
$('#adventures_tab').toggle(!(isCodeTab && $('#developers_toggle').is(":checked")));
$('#developers_toggle_container').toggle(isCodeTab);
$('#level_header input').toggle(isCodeTab);
$('#parsons_code_container').toggle(isParsonsTab);
$('#editor_area').toggle(isCodeTab || isParsonsTab);
$('#parsons_code_container').toggle(currentTab === 'parsons');
$('#editor_area').toggle(isCodeTab || currentTab === 'parsons');
$('#editor').toggle(isCodeTab);
$('#debug_container').toggle(isCodeTab);
$('#program_name_container').toggle(isCodeTab);
Expand Down Expand Up @@ -1727,9 +1762,7 @@ function updatePageElements() {
$('#commands_dropdown_container').show()
$('#hand_in_button').show()
}
if (currentTab === 'parsons'){
$('[data-view="if-submitted"]').toggle(false);
$('[data-view="if-not-submitted"]').toggle(true);
if (currentTab === 'parsons'){
$('#share_program_button').hide()
$('#read_outloud_button_container').hide()
$('#cheatsheet_dropdown_container').hide()
Expand All @@ -1749,36 +1782,23 @@ function updatePageElements() {
/**
* After switching tabs, show/hide elements
*/
function reconfigurePageBasedOnTab() {
function reconfigurePageBasedOnTab(enforceDevMode?: boolean) {
resetWindow();

updatePageElements();

toggleDevelopersMode(!!enforceDevMode);
if (currentTab === 'parsons') {
loadParsonsExercise(theLevel, 1);
// parsons could have 5 lines to arrange which requires more space, so remove the fixed height from the editor
// remove the fixed height from the editor
document.getElementById('code_editor')!.style.height = '100%'
document.getElementById('code_output')!.style.height = '100%'
return;
}

// only relevant for the old hedy page; remove lines below when we migrate to tryit
show_editor();
$('#fold_in_toggle_container').hide();
} else {
// deriving from HTML attributes is more flexible on what gets resized, and avoids duplicating
// size literals between HTML and JavaScript.
$('[data-editorheight]').each((_, el) => {
const height = $(el).data('editorheight');
$(el).css('height', height);
});

// only relevant for the old hedy page; remove lines below when we migrate to tryit
$('#fold_in_toggle_container').show();

const adventure = theAdventures[currentTab];
if (adventure) {
$ ('#program_name').val(adventure.save_name);
theGlobalEditor.contents = adventure.editor_contents;
}
const adventure = theAdventures[currentTab];
if (adventure) {
$ ('#program_name').val(adventure.save_name);
theGlobalEditor.contents = adventure.editor_contents;
}
}

Expand Down
65 changes: 42 additions & 23 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60650,6 +60650,7 @@ ${o3}` : i3;
save_customizations: () => save_customizations,
select_profile_image: () => select_profile_image,
setDateLevelInputColor: () => setDateLevelInputColor,
setDevelopersMode: () => setDevelopersMode,
set_explore_favourite: () => set_explore_favourite,
set_favourite_program: () => set_favourite_program,
show_doc_section: () => show_doc_section,
Expand Down Expand Up @@ -120737,7 +120738,7 @@ def note_with_error(value, err):
adventure.save_info = "local-storage";
}
}
reconfigurePageBasedOnTab();
reconfigurePageBasedOnTab(options.enforce_developers_mode);
checkNow();
theLocalSaveWarning.switchTab();
});
Expand Down Expand Up @@ -121636,6 +121637,33 @@ def note_with_error(value, err):
let title = ClientMessages["Program_repair"];
modal.repair(editor, 0, title);
}
function setDevelopersMode(event2 = "click", enforceDevMode) {
let enable = false;
switch (event2) {
case "load":
const lastSelection = window.localStorage.getItem("developer_mode") === "true";
enable = enforceDevMode || lastSelection;
$("#developers_toggle").prop("checked", enable);
break;
case "click":
enable = $("#developers_toggle").prop("checked");
break;
}
if (!enforceDevMode)
window.localStorage.setItem("developer_mode", `${enable}`);
toggleDevelopersMode(!!enforceDevMode);
}
function toggleDevelopersMode(enforceDevMode) {
const enable = window.localStorage.getItem("developer_mode") === "true" || enforceDevMode;
$("#adventures_tab").toggle(!enable || currentTab === "quiz" || currentTab === "parsons");
$("#adventures").toggle(!enable || currentTab === "quiz" || currentTab === "parsons");
if (currentTab === "parsons")
return;
$("[data-devmodeheight]").each((_, el3) => {
const heights = $(el3).data("devmodeheight").split(",");
$(el3).css("height", heights[enable ? 1 : 0]);
});
}
function saveForTeacherTable(table) {
let show_table = window.localStorage.getItem(table);
window.localStorage.setItem(table, (show_table !== "true").toString());
Expand Down Expand Up @@ -121825,13 +121853,12 @@ def note_with_error(value, err):
}
function updatePageElements() {
var _a3;
const isParsonsTab = currentTab === "parsons";
const isCodeTab = !(currentTab === "quiz" || isParsonsTab);
$("#adventures_tab").toggle(true);
$("#adventures").toggle(true);
const isCodeTab = !(currentTab === "quiz" || currentTab === "parsons");
$("#adventures_tab").toggle(!(isCodeTab && $("#developers_toggle").is(":checked")));
$("#developers_toggle_container").toggle(isCodeTab);
$("#level_header input").toggle(isCodeTab);
$("#parsons_code_container").toggle(isParsonsTab);
$("#editor_area").toggle(isCodeTab || isParsonsTab);
$("#parsons_code_container").toggle(currentTab === "parsons");
$("#editor_area").toggle(isCodeTab || currentTab === "parsons");
$("#editor").toggle(isCodeTab);
$("#debug_container").toggle(isCodeTab);
$("#program_name_container").toggle(isCodeTab);
Expand Down Expand Up @@ -121859,8 +121886,6 @@ def note_with_error(value, err):
$("#hand_in_button").show();
}
if (currentTab === "parsons") {
$('[data-view="if-submitted"]').toggle(false);
$('[data-view="if-not-submitted"]').toggle(true);
$("#share_program_button").hide();
$("#read_outloud_button_container").hide();
$("#cheatsheet_dropdown_container").hide();
Expand All @@ -121876,26 +121901,20 @@ def note_with_error(value, err):
$("#hand_in_button").hide();
}
}
function reconfigurePageBasedOnTab() {
function reconfigurePageBasedOnTab(enforceDevMode) {
resetWindow();
updatePageElements();
toggleDevelopersMode(!!enforceDevMode);
if (currentTab === "parsons") {
loadParsonsExercise(theLevel, 1);
document.getElementById("code_editor").style.height = "100%";
document.getElementById("code_output").style.height = "100%";
show_editor();
$("#fold_in_toggle_container").hide();
} else {
$("[data-editorheight]").each((_, el3) => {
const height = $(el3).data("editorheight");
$(el3).css("height", height);
});
$("#fold_in_toggle_container").show();
const adventure = theAdventures[currentTab];
if (adventure) {
$("#program_name").val(adventure.save_name);
theGlobalEditor.contents = adventure.editor_contents;
}
return;
}
const adventure = theAdventures[currentTab];
if (adventure) {
$("#program_name").val(adventure.save_name);
theGlobalEditor.contents = adventure.editor_contents;
}
}
function closeContainingModal(target) {
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions templates/customize-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ <h3 class="px-4"><u>{{_('other_settings')}}</u></h3>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left border-t border-r border-gray-400">{{_('mandatory_mode')}}</td>
<td class="border-t border-gray-400">
<input class="other_settings_checkbox" id="developers_mode" data-cy="developers_mode" type="checkbox" {%
if "developers_mode" in customizations['other_settings'] %}checked{% endif %}>
</td>
</tr>
<tr>
<td class="text-left border-t border-r border-gray-400">{{_('all_class_highscores')}}
</td>
Expand Down
Loading

0 comments on commit a7314c1

Please sign in to comment.