Skip to content

Commit

Permalink
Merge pull request #521 from matematikk-mooc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
madsenandreas authored Apr 23, 2024
2 parents 341c6cd + 0c4b6e0 commit 90566af
Show file tree
Hide file tree
Showing 31 changed files with 3,934 additions and 4,102 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/build-dev-push-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ on:
push:
branches:
- dev
workflow_dispatch:

env:
ACCOUNT_NAME: udirdit
SOURCE: dist
DESTINATION: frontend-dev
AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

Expand All @@ -29,14 +32,14 @@ jobs:
run: yarn buildDev

- name: Login to Azure
uses: azure/login@v1
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Upload files to Azure Blob
uses: azure/CLI@v1
uses: azure/CLI@v2
with:
azcliversion: 2.48.1
azcliversion: 2.34.1
inlineScript: |
az storage blob upload-batch --account-name ${{ env.ACCOUNT_NAME }} \
--auth-mode key -s ${{ env.SOURCE }} -d ${{ env.DESTINATION }} --overwrite
Expand Down
29 changes: 16 additions & 13 deletions .github/workflows/build-master-push-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ on:
push:
branches:
- master
workflow_dispatch:

env:
ACCOUNT_NAME: udirdit
SOURCE: dist
DESTINATION: frontend-master
AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

Expand All @@ -29,25 +32,25 @@ jobs:
run: yarn buildProduction

- name: Login to Azure
uses: azure/login@v1
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Upload files to Azure Blob
uses: azure/CLI@v1
uses: azure/CLI@v2
with:
azcliversion: 2.48.1
azcliversion: 2.34.1
inlineScript: |
az storage blob upload-batch --account-name ${{ env.ACCOUNT_NAME }} \
--auth-mode key -s ${{ env.SOURCE }} -d ${{ env.DESTINATION }} --overwrite
az storage blob upload-batch --account-name ${{ env.ACCOUNT_NAME }} \
--auth-mode key -s ${{ env.SOURCE }} -d ${{ env.DESTINATION }} --overwrite
az storage blob list --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --query "[?ends_with(name, '.woff')].{Name:name}" --output tsv | \
xargs -I {} az storage blob update --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --name {} --content-type "application/font-woff"
az storage blob list --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --query "[?ends_with(name, '.woff')].{Name:name}" --output tsv | \
xargs -I {} az storage blob update --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --name {} --content-type "application/font-woff"
az storage blob list --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --query "[?ends_with(name, '.woff2')].{Name:name}" --output tsv | \
xargs -I {} az storage blob update --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --name {} --content-type "font/woff2"
az storage blob list --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --query "[?ends_with(name, '.woff2')].{Name:name}" --output tsv | \
xargs -I {} az storage blob update --account-name ${{ env.ACCOUNT_NAME }} --container-name ${{ env.DESTINATION }} --name {} --content-type "font/woff2"
# Azure logout - Force step to always run with 'always()', ensures no hanging logins
- name: logout
if: always()
run: |
az logout
az logout
115 changes: 115 additions & 0 deletions src/js/account-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import LoginDirectLink from '../vue/components/login-choice/LoginDirectLink.vue';
import { createApp } from 'vue';
import utilRoot from './utilRoot';

var udirDesignLoaded;


jQuery.extend({
getScript: function (url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;

// Handle Script loading
{
var done = false;

// Attach handlers for all browsers
script.onload = script.onreadystatechange = function () {
if (
!done &&
(!this.readyState ||
this.readyState == "loaded" ||
this.readyState == "complete")
) {
done = true;
if (callback) callback();

// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
}
};
}

head.appendChild(script);

// We handle everything using the script element injection
return undefined;
},
});

jQuery(document).ready(function ($) {
console.log("START.");

var redirected = false;

// Redirect if necessary
if (document.location.pathname == "/search/all_courses" && document.location.search.includes('?enroll_code')) {
window.location.href = '/courses' + document.location.search;
redirected = true;
} else if (document.location.pathname == "/login/canvas") {
if (document.referrer.includes("/logout")) {
window.location.href = '/search/all_courses';
redirected = true;
} else if (!document.referrer.includes("/login/canvas")) {
$(".ic-Login").hide();
$("#f1_container").hide(); // Small screens
redirected = utilRoot.redirectFeideAuthIfEnrollReferrer();
if (!redirected) {
if (!document.location.search.includes("normalLogin=1")) {
document.getElementById('wrapper').remove();
let parent = document.getElementById('application');
let login = document.createElement('div');
login.id = 'login-component';
let customLogin = createApp(LoginDirectLink);
parent.appendChild(login);
customLogin.mount("#login-component");
} else {
$(".ic-Login").show();
$("#f1_container").show(); // Small screens
}
}
}
} else if (document.location.pathname == "/courses") {
redirected = utilRoot.redirectToEnrollIfCodeParamPassed();
} else if (document.location.href.indexOf('?login_success=1') != -1) {
window.location.href = '/search/all_courses';
} else if (document.location.pathname == "/") {
setTimeout(function () {
if (!$(".ic-DashboardCard__header_hero").length) {
let html = `
<div class="card card-body">
<h3>Er det tomt her?</h3>
<p>Dersom du har valgt å logge inn med Feide og ikke finner innholdet ditt kan det hende det er fordi du
vanligvis har logget på med en annen bruker ved å bruke epost og passord. Logg ut og inn igjen ved å benytte "Ikke Feide" - knappen.
</p>
<img src="${SERVER}bitmaps/nyinnlogging.png" width="70%" alt="Ny innloggingsskjerm"/>
</div>
`;
document.getElementById('dashboard-activity').insertAdjacentHTML('beforebegin', html);
}
}, 1000)
}

if (!redirected) {
if (window.udirDesignLoaded === undefined) {
window.udirDesignLoaded = true;
console.log("Loading udir design.");

var filename = SERVER + DESIGNCSS;

var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
fileref.onload = (_) => {
$.getScript(SERVER + DESIGNJS);
}
document.getElementsByTagName("head")[0].appendChild(fileref)
} else {
console.log("Udir design already loaded.");
}
}

});
2 changes: 1 addition & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jQuery(function($) {
if (document.location.search === '?mmpf') {
mmooc.powerFunctions.show(parentId);
} else {
window.location.href = '/courses?design=udir';
window.location.href = '/courses';
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/courselist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default (function () {
var myCoursesWithSettings = util.mapCourseSettings(courses, allCoursesSettings.result);

if (courses.length == 0) {
window.location.href = "/search/all_courses?design=udir";
window.location.href = "/search/all_courses";
} else {


Expand Down
4 changes: 1 addition & 3 deletions src/js/modules/coursepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ export default (function() {
showCourseInvitation: function () {
if (!util.isAuthenticated()) {
var enrollButton = $(".course_enrollment_link");
var linkToSelectedCourse = window.location.href.split('/');
var selectedCourseId = linkToSelectedCourse[linkToSelectedCourse.length - 1];

if (enrollButton) {
enrollButton.text('Enroll this course');
enrollButton.click(function (e) {
e.preventDefault();
window.location.href = '/search/all_courses' + '?design=udir' + '#' + selectedCourseId;
window.location.href = '/search/all_courses';
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/modules/enroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import LoggedInLandingPage from "../../vue/pages/LoggedInLandingPage.vue";
import NotLoggedInPage from "../../vue/pages/NotLoggedInPage.vue";
import api from "../api/api";
import { createApp } from "vue/dist/vue.runtime.esm-bundler.js";
import { hrefQueryString } from "../settingsRoot";
import kpasApi from "../api/kpas-api";
import settings from "../settings";
import util from "./util";
Expand Down Expand Up @@ -60,7 +59,7 @@ export default (function () {
if ($this.hasClass('btn-primary')){
var _href = $this.attr("href");
}else {
var _href = $this.attr("href") + hrefQueryString;
var _href = $this.attr("href");
}

const urlParamsObj = utilRoot.urlParamsToObject();
Expand Down
6 changes: 2 additions & 4 deletions src/js/modules/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { hrefAmpQueryString, hrefQueryString } from "../settingsRoot";

import api from '../api/api.js'
import settings from "../settings";

Expand Down Expand Up @@ -477,7 +475,7 @@ export default (function () {
$this.remove();
}
else{
$this.attr("href", _href + hrefAmpQueryString);
$this.attr("href", _href);
}
});
},
Expand All @@ -488,7 +486,7 @@ export default (function () {
});
},
getLinkToAvailableCourses: function () {
var linkToAvailableCourses = "/search/all_courses" + hrefQueryString;
var linkToAvailableCourses = "/search/all_courses";
//ETH20190409 By making sure the root account loads our design, we do not need a front page.
/*
if (allCoursesFrontpageCourseID > 0) {
Expand Down
Loading

0 comments on commit 90566af

Please sign in to comment.