Skip to content

Commit

Permalink
Merge branch 'release/6.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Aug 26, 2022
2 parents 5358643 + d912370 commit 635bcdb
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 11 deletions.
78 changes: 71 additions & 7 deletions app/assets/javascripts/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class SearchQuery {
appliedIndex = 0;
arrayQueryParams: QueryParameters<string[]> = new QueryParameters<string[]>();
queryParams: QueryParameters<string> = new QueryParameters<string>();
localStorageKey?: string;

setRefreshElement(refreshElement: string): void {
this.refreshElement = refreshElement;
Expand Down Expand Up @@ -87,13 +88,13 @@ export class SearchQuery {
}

// initialise present parameters
for (const key of url.searchParams.keys()) {
if (key.endsWith("[]")) {
this.arrayQueryParams.updateParam(key.substring(0, key.length-2), url.searchParams.getAll(key));
} else {
this.queryParams.updateParam(key, url.searchParams.get(key));
}
}
this.initialiseParams(url.searchParams);
}

setLocalStorageKey(localStorageKey: string): void {
this.localStorageKey = localStorageKey;
// apply parameters from local storage
this.useLocalStorage();
}

initPagination(): void {
Expand Down Expand Up @@ -194,8 +195,71 @@ export class SearchQuery {
eval(data);
}
document.getElementById("progress-filter").style.visibility = "hidden";

// if there is local storage key => update the value to reuse later
if (this.localStorageKey) {
const urlObj = new URL(url);
localStorage.setItem(this.localStorageKey, urlObj.searchParams.toString());
}
});
}

/**
* fetch params from localStorage using the localStorageKey if present and apply them to the current url
*/
useLocalStorage() : void {
if (this.localStorageKey) {
const searchParamsStringFromStorage = localStorage.getItem(this.localStorageKey);
if (searchParamsStringFromStorage) {
const searchParamsFromStorage = new URLSearchParams(searchParamsStringFromStorage);
// don't overwrite currently set params with params from the localStorage
searchParamsFromStorage.forEach((_value: string, key:string) => {
if (this.queryParams.params.get(key) !== undefined ||
(this.isArrayQueryParamsKey(key) &&
this.arrayQueryParams.params.get(this.extractArrayQueryParamsKey(key)) !== undefined)) {
searchParamsFromStorage.delete(key);
}
});

this.initialiseParams(searchParamsFromStorage);
}
}
}

/**
* @param {URLSearchParams} searchParams the obj whose params we want to use
*
* apply the param values from the URLSearchParams obj to the current queryParams and arrayQueryParams
*/
initialiseParams(searchParams: URLSearchParams) : void {
for (const key of searchParams.keys()) {
if (this.isArrayQueryParamsKey(key)) {
this.arrayQueryParams.updateParam(this.extractArrayQueryParamsKey(key), searchParams.getAll(key));
} else {
this.queryParams.updateParam(key, searchParams.get(key));
}
}
}

/**
*
* @param {string} key the key value stored in the url
* @private
* @return {boolean} true if the key ends with [] otherwise false
*/
private isArrayQueryParamsKey(key: string): boolean {
return key.endsWith("[]");
}

/**
*
* @param {string} key the key value stored in the url
* @private
* @return {string} the key without the [] at the end
*/
private extractArrayQueryParamsKey(key: string): string {
return key.substring(0, key.length-2);
}
}

dodona.searchQuery = dodona.searchQuery || new SearchQuery();
Expand Down
2 changes: 1 addition & 1 deletion app/models/provider/g_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def readable_name
# We want to display gmail for private accounts
return 'Gmail' if institution.nil?

super.readable_name
super
end
end
7 changes: 6 additions & 1 deletion app/views/layouts/_searchbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
multi: false,
data: <%= raw render template: 'programming_languages/index', formats: :json %>,
color: function () {
return "teal";
return "red";
},
};
<% end %>
Expand Down Expand Up @@ -171,8 +171,13 @@
}
};
<% end %>

dodona.searchQuery.setRefreshElement("<%= local_assigns.fetch :refresh_element, "" %>");

// load the given localStorageKey if present. This key is used to retrieve the values stored in localStorage
const localStorageKey = "<%= local_assigns.fetch :local_storage_key, "" %>"
dodona.searchQuery.setBaseUrl("<%= local_assigns.fetch :baseUrl, "" %>");
dodona.searchQuery.setLocalStorageKey(localStorageKey);

const searchFields = Array.from(document.getElementsByTagName("d-search-field"));
searchFields.forEach( searchField => {
Expand Down
2 changes: 1 addition & 1 deletion app/views/series/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<div class="card-supporting-text card-border">
<div class="col-12">
<h4 id="add-activities"><%= t ".add_activities" %></h4>
<%= render partial: 'layouts/searchbar', locals: {baseUrl: available_activities_series_path(@series), eager: true, labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"]} %>
<%= render partial: 'layouts/searchbar', locals: {baseUrl: available_activities_series_path(@series), eager: true, labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"], local_storage_key: 'seriesActivitySearch'} %>
<div id="activities-table-wrapper">
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/00_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Application
module Version
MAJOR = 6
MINOR = 0
PATCH = 2
PATCH = 3

STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
Expand Down
5 changes: 5 additions & 0 deletions test/models/provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class ProviderTest < ActiveSupport::TestCase
assert_equal DEFAULT_NAMES, provider.extract_institution_name(OmniAuth::AuthHash.new({ info: {} }))
end

test 'gsuite readable_name gives Google Workspace as name when account is NOT private' do
provider = build :gsuite_provider, institution: @institution
assert_equal Provider::GSuite.readable_name, provider.readable_name
end

test 'smartschool extracts name of institution' do
provider = Provider::Smartschool
# This hash is extracted from the one we receive when logging in.
Expand Down

0 comments on commit 635bcdb

Please sign in to comment.