Skip to content

Commit

Permalink
Merge pull request #94 from MatsMoll/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MatsMoll authored Nov 18, 2022
2 parents 188069b + e1a44b4 commit e6a53ea
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 121 deletions.
21 changes: 0 additions & 21 deletions Makefile

This file was deleted.

23 changes: 14 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import Foundation

var dependencies: [Package.Dependency] = [
// 💧 A server-side Swift web framework.
.package(name: "vapor", url: "https://github.com/vapor/vapor.git", from: "4.29.0"),
.package(name: "vapor", url: "https://github.com/vapor/vapor.git", from: "4.67.3"),

.package(name: "HTMLKitVaporProvider", url: "https://github.com/MatsMoll/htmlkit-vapor-provider.git", from: "1.0.1"),
.package(name: "HTMLKitVaporProvider", url: "https://github.com/MatsMoll/htmlkit-vapor-provider.git", .exact("1.0.1")),

.package(url: "https://github.com/vapor-community/HTMLKit.git", from: "2.1.0"),
.package(url: "https://github.com/vapor-community/HTMLKit.git", .exact("2.1.1")),

.package(name: "RediStack", url: "https://github.com/Mordil/RediStack", from: "1.3.0"),

.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.15.0"),
]

// Kognita Core


switch ProcessInfo.processInfo.environment["BUILD_TYPE"] {
case "LOCAL":
dependencies.append(contentsOf: [
Expand All @@ -23,9 +28,9 @@ case "LOCAL":
)
case "DEV":
dependencies.append(contentsOf: [
.package(name: "KognitaCore", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/KognitaCore", .branch("develop")),
.package(name: "KognitaViews", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/KognitaPages", .branch("develop")),
.package(name: "KognitaAPI", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/kognita-rest-api", .branch("develop"))
.package(name: "KognitaCore", url: "https://github.com/MatsMoll/KognitaCore", .branch("develop")),
.package(name: "KognitaViews", url: "https://github.com/MatsMoll/KognitaPages", .branch("develop")),
.package(name: "KognitaAPI", url: "https://github.com/MatsMoll/kognita-rest-api", .branch("develop"))
]
)
default:
Expand All @@ -45,9 +50,9 @@ default:
let pagesVersion = ProcessInfo.processInfo.environment["KOGNITA_PAGES"] ?? "2.0.0"
let apiVersion = ProcessInfo.processInfo.environment["KOGNITA_API"] ?? "2.0.0"
dependencies.append(contentsOf: [
.package(name: "KognitaCore", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/KognitaCore", from: Version(stringLiteral: coreVersion)),
.package(name: "KognitaViews", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/KognitaPages", from: Version(stringLiteral: pagesVersion)),
.package(name: "KognitaAPI", url: "https://Kognita:dyjdov-bupgev-goffY8@github.com/MatsMoll/kognita-rest-api", from: Version(stringLiteral: apiVersion))
.package(name: "KognitaCore", url: "https://github.com/MatsMoll/KognitaCore", from: Version(stringLiteral: coreVersion)),
.package(name: "KognitaViews", url: "https://github.com/MatsMoll/KognitaPages", from: Version(stringLiteral: pagesVersion)),
.package(name: "KognitaAPI", url: "https://github.com/MatsMoll/kognita-rest-api", from: Version(stringLiteral: apiVersion))
]
)
}
Expand Down
3 changes: 2 additions & 1 deletion Public/assets/js/flash-card/json-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function jsonData() {
"subtopicId" : subtopicId,
"description" : descriptionValue,
"question" : question,
"solution" : solutionValue
"solution" : solutionValue,
"resources": []
});
}
10 changes: 6 additions & 4 deletions Public/assets/js/multiple-choise/json-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ function jsonData() {
if (choises.filter(choise => choise.isCorrect).length < 1) {
throw Error("Minst et alternativ må være markert som riktig. Dette kan gjøres ved å trykke på det riktige alternativet")
}

console.log(choises);
if (isTestable == null) {
isTestable = false
}

return JSON.stringify({
"isTestable" : isTestable,
Expand All @@ -49,6 +50,7 @@ function jsonData() {
"question" : question,
"isMultipleSelect" : isMultipleSelect,
"choises" : choises,
"solution" : solutionValue
"solution" : solutionValue,
"resources": []
});
}
}
50 changes: 37 additions & 13 deletions Public/assets/js/resources/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ function createResource() {

let connectedID = document.getElementById("resource-connect-id").value;
let connectionType = document.getElementById("resource-connect-type").value;
let inputName = document.getElementById("resource-input-name").value;
let formName = document.getElementById("resource-form-name").value;

var url = "/api/resources/"
var jsonData;

if (resourceTabID == "article-rec") {
url += "article"
jsonData = articleData(title)
} else if (resourceTabID == "video-rec") {
url += "video"
jsonData = videoData(title)
} else if (resourceTabID == "book-rec") {
url += "book"
jsonData = bookData(title)
} else {
return
try {
if (title.length == 0) {
throw new Error("Ups! Mangler tittel");
}
if (resourceTabID == "article-rec") {
url += "article"
jsonData = articleData(title)
} else if (resourceTabID == "video-rec") {
url += "video"
jsonData = videoData(title)
} else if (resourceTabID == "book-rec") {
url += "book"
jsonData = bookData(title)
} else {
return
}
} catch (error) {
console.log(error);
$("#resource-form").addClass("was-validated");
}

fetch(url, {
Expand All @@ -33,6 +43,7 @@ function createResource() {
})
.then(function (response) {
if (response.ok) {
$("#create-resource-modal").modal('hide');
return response.json();
} else if (response.status == 400) {
throw new Error("Sjekk at all nødvendig info er fylt ut");
Expand All @@ -46,7 +57,14 @@ function createResource() {
console.log("Not a number");
return
}
if (connectionType == "term") {
if (inputName.length != 0 && formName.length != 0) {
let form = document.getElementById(formName);
var input = document.createElement("input");
input.type = "hidden";
input.name = inputName + "[]";
input.value = json;
form.appendChild(input);
} else if (connectionType == "term") {
connectTerm(connectedID, json);
} else if (connectionType == "subtopic") {
connectSubtopic(connectedID, json);
Expand All @@ -62,7 +80,9 @@ function videoData(title) {
if (isNaN(duration)) {
duration = null;
}

if (url.length == 0 || creator.length == 0) {
throw Error("Ups! Mangeler noe data");
}
return JSON.stringify({
"url": url,
"creator": creator,
Expand All @@ -79,6 +99,10 @@ function articleData(title) {
let url = document.getElementById("article-url").value;
let author = document.getElementById("article-author").value;

if (url.length == 0 || author.length == 0) {
throw new Error("Ups! Noe data mangler");
}

return JSON.stringify({
"url": url,
"author": author,
Expand Down
25 changes: 12 additions & 13 deletions Sources/App/Creator/CreatorWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Vapor
import KognitaCore
import KognitaViews
import QTIKit

final class CreatorWebController: RouteCollection {

Expand Down Expand Up @@ -91,18 +90,18 @@ final class CreatorWebController: RouteCollection {
let files: [File]
}

private func decodeAssessmentItems(from files: [File]) -> [AssessmentItem] {
var assessmentItems = [AssessmentItem]()
for file in files {
guard
let data = file.data.getData(at: 0, length: file.data.readableBytes),
let xml = String(data: data, encoding: .utf8),
let item = try? QTIKit.assessmentItem(withXML: xml)
else { continue }
assessmentItems.append(item)
}
return assessmentItems
}
// private func decodeAssessmentItems(from files: [File]) -> [AssessmentItem] {
// var assessmentItems = [AssessmentItem]()
// for file in files {
// guard
// let data = file.data.getData(at: 0, length: file.data.readableBytes),
// let xml = String(data: data, encoding: .utf8),
// let item = try? QTIKit.assessmentItem(withXML: xml)
// else { continue }
// assessmentItems.append(item)
// }
// return assessmentItems
// }

// func importQTIContent(on req: Request) throws -> EventLoopFuture<Response> {
//
Expand Down
18 changes: 12 additions & 6 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ private func setupUserWeb(for app: Application) throws {
let redirectMiddle = sessionMiddle.grouped(RedirectMiddleware<User>(path: "/login"))

sessionMiddle.get { req -> EventLoopFuture<Response> in
if req.auth.get(User.self) != nil {
return req.eventLoop.future(req.redirect(to: "/subjects"))

req.repositories(transaction: { repo in
repo.userRepository.numberOfUsers().and(repo.taskResultRepository.numberOfCompletedTasks())
})
.flatMapThrowing { (numberOfUsers, numberOfCompletedTasks) -> Response in
let context = Pages.Landing.Context(
showCookieMessage: req.cookies.isAccepted == false,
numberOfCompletedTasks: numberOfCompletedTasks,
numberOfUsers: numberOfUsers
)

return try req.htmlkit.render(Pages.Landing.self, with: context)
}
let context = Pages.Landing.Context(showCookieMessage: req.cookies.isAccepted == false)

return try req.htmlkit.render(view: Pages.Landing.self, with: context)
.encodeResponse(for: req)
}

app.get("privacy-policy") { req -> View in
Expand Down
5 changes: 0 additions & 5 deletions develop.sh

This file was deleted.

4 changes: 0 additions & 4 deletions install.sh

This file was deleted.

45 changes: 0 additions & 45 deletions set-xcodeproj-env.py

This file was deleted.

0 comments on commit e6a53ea

Please sign in to comment.