| 33 | } |
| 34 | |
| 35 | void MOOCAssignment::loadJSON(const QJsonObject& obj, const QFileInfo& fi) |
| 36 | { |
| 37 | if (obj.isEmpty() || |
| 38 | !obj["assignmentKey"].isString() || !obj["name"].isString() || !obj["moocName"].isString() || |
| 39 | !obj["moocPasswordString"].isString() || !obj["submissionURL"].isString() || |
| 40 | !obj["solutionAssignments"].isArray() || !obj["modelAssignments"].isArray()) { |
| 41 | throw MoocError("Could not parse mooc file"); |
| 42 | } |
| 43 | |
| 44 | assignmentKey = obj["assignmentKey"].toString(); |
| 45 | name = obj["name"].toString(); |
| 46 | moocName = obj["moocName"].toString(); |
| 47 | moocPasswordString = obj["moocPasswordString"].toString(); |
| 48 | submissionURL = obj["submissionURL"].toString(); |
| 49 | submissionTerms = obj["submissionTerms"].toString(); |
| 50 | sendMeta = obj["sendMeta"].toBool(false); |
| 51 | QJsonArray sols = obj["solutionAssignments"].toArray(); |
| 52 | for (int i=0; i<sols.size(); i++) { |
| 53 | QJsonObject solO = sols[i].toObject(); |
| 54 | if (!sols[i].isObject() || !solO["id"].isString() || !solO["model"].isString() || |
| 55 | !solO["data"].isString() || (!solO["timeout"].isDouble() && !solO["timeout"].isString() ) || !solO["name"].isString()) { |
| 56 | throw MoocError("Could not parse mooc file"); |
| 57 | } |
| 58 | |
| 59 | QString timeout = solO["timeout"].isDouble() ? QString::number(solO["timeout"].toInt()) : solO["timeout"].toString(); |
| 60 | QFileInfo model_fi(fi.dir(), solO["model"].toString()); |
| 61 | QFileInfo data_fi(fi.dir(), solO["data"].toString()); |
| 62 | MOOCAssignmentItem item(solO["id"].toString(), model_fi.absoluteFilePath(), data_fi.absoluteFilePath(), |
| 63 | timeout, solO["name"].toString(), solO["required"].toBool(false)); |
| 64 | problems.append(item); |
| 65 | } |
| 66 | QJsonArray modelsArray = obj["modelAssignments"].toArray(); |
| 67 | for (int i=0; i<modelsArray.size(); i++) { |
| 68 | QJsonObject modelO = modelsArray[i].toObject(); |
| 69 | QFileInfo model_fi(fi.dir(), modelO["model"].toString()); |
| 70 | MOOCAssignmentItem item(modelO["id"].toString(), model_fi.absoluteFilePath(), modelO["name"].toString(), modelO["required"].toBool(false)); |
| 71 | models.append(item); |
| 72 | } |
| 73 | |
| 74 | json = obj; |
| 75 | if (obj["history"].isObject()) { |
| 76 | history = new History(obj["history"].toObject(), fi.absoluteDir()); |
| 77 | QObject::connect(IDE::instance(), &IDE::reloadedFile, history, &History::updateFileContents); |
| 78 | QObject::connect(history, &History::historyChanged, [=] () { |
| 79 | json["history"] = history->toJSON(); |
| 80 | QFile file(moocFile); |
| 81 | if (file.open(QFile::WriteOnly)) { |
| 82 | file.write(QJsonDocument(json).toJson()); |
| 83 | file.close(); |
| 84 | } |
| 85 | }); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | MOOCSubmission::MOOCSubmission(MainWindow* mw0, MOOCAssignment& cp) : |
| 90 | QDialog(nullptr), _cur_phase(S_NONE), project(cp), mw(mw0), |