Commit e84de536ad0707486d6adccc1ff428a5803ff2a0

First working version of lti instance with 'use_lti': false. Minor additions to CSS.
timApp/modules/lti/css/lti.css
(5 / 0)
  
1818 justify-content: space-between;
1919 margin: 5px 10px;
2020}
21
22.lti-text > p.login-text {
23 color: rgb(122, 122, 122);
24 margin: 10px;
25}
timApp/modules/lti/js/lti.js
(41 / 17)
  
4444 'Aloita alusta' +
4545 '</button>' +
4646 // Default state
47 '<button ng-if="' + "state === 'default' && use_lti" + '" class="btn btn-success" ng-click="run()">' +
47 '<button ng-if="' + "state === 'default'" + '" class="btn btn-success" ng-click="run()">' +
4848 'Aloita' +
4949 '</button>' +
50 // Login
51 '<button ng-if="' + "state === 'default' && !use_lti" + '" class="btn btn-success" ng-click="runNoLTI()">' +
52 'Aloita kirjautumalla sisään' +
53 '</button>' +
5450 // Inactive state
5551 '<button ng-if="' + "state === 'inactive'" + '" class="btn btn-danger" ng-click="forceOpen()">' +
5652 'Lopeta aiempi ja aloita' +
8181 '</iframe>' +
8282
8383 '<div class="lti lti-text">' +
84 '<p ng-if="!use_lti" class="login-text">' +
85 'Jos et ole kirjautunut Moodleen, ' +
86 '<button ng-click="openLoginPage()">' +
87 'kirjaudu ensin sisään' +
88 '</button>. ' +
89 'Tämän jälkeen voit aloittaa tehtävän painamalla "Aloita".</p>' +
90 '<p ng-if="!use_lti" class="login-text">Jos jokin muu tehtävä tulee esiin, voit siirtyä oikeean tehtävään "Aloita" tai "Aloita alusta" painikkeilla.' +
91 '</p>' +
8492 '<pre class="lti" ng-if="isInactive()">{{::inactiveText}}</pre>' +
8593 '<pre ng-if="use_js && use_lti" class="lti">Pisteesi tehtävästä: {{grade}}</pre>' +
8694 '</div>' +
221221 };
222222
223223 $scope.updateGrade = function() {
224 $http.get("/lti/grades?hash=" + $scope.hash)
224 $http.get("../lti/grades?hash=" + $scope.hash)
225225 .then(function(res) {
226226 var newGrade = res.data;
227227 var lastSaved = $scope.lastSaved;
237237
238238 // Called when "Aja" button is pressed.
239239 $scope.run = function() {
240 $scope.iframe.src = $sce.trustAsResourceUrl('/lti/getform?hash=' + $scope.hash);
240 var url = "";
241 if ($scope.use_lti) {
242 url = $sce.trustAsResourceUrl('../lti/getform?hash=' + $scope.hash);
243 //$scope.iframe.src = url;
244 } else {
245 url = $sce.trustAsResourceUrl('../lti/getlink?page=' + $scope.view_url);
246 //$scope.reload(url, false);
247 }
248 $scope.iframe.src = url;
241249 ltiApp.container.update($scope, 'active');
242250 };
243251
244 $scope.runNoLTI = function() {
245 console.log($scope.view_url)
246 $scope.iframe.src = $sce.trustAsResourceUrl($scope.view_url);
247 ltiApp.container.update($scope, 'active');
252 $scope.openLoginPage = function() {
253 var url = $sce.trustAsResourceUrl('../lti/getlink?page=' + $scope.login_url);
254 if (!$scope.iframe.src) {
255 $scope.iframe.src = url;
256 } else {
257 $scope.reload(url, false); // Forces the <iframe> to load login page always.
258 }
248259 };
249260
250261 $scope.close = function() {
267267 return is_sure;
268268 };
269269
270 $scope.reload = function() {
271 var is_sure = confirm("Menetät työsi aloittamalla tehtävän uudestaan. Oletko varma?");
272 if (is_sure) {
273 document.getElementById($scope.iframe.id).src = $scope.iframe.src;
270 $scope.reload = function(url, confirmation) {
271 url = url || $scope.iframe.src;
272 if (confirmation === true || confirmation === undefined) {
273 var is_sure = confirm("Menetät työsi aloittamalla tehtävän uudestaan. Oletko varma?");
274274 }
275 if (!confirmation || is_sure) {
276 document.getElementById($scope.iframe.id).src = url;
277 } else {
278 $scope.iframe.src = url;
279 }
275280 };
276281
277282 $scope.forceOpen = function() {
311311
312312 // Etsitään kullekin attribuutille arvo joko scope.attrs tai attrs-parametrista. Jos ei ole, käytetään oletusta.
313313 timHelper.set(scope, attrs, "stem");
314 timHelper.set(scope, attrs, "hash", undefined); // 'use_lti': true
315 timHelper.set(scope, attrs, "view_url", undefined); // 'use_lti': false
314 timHelper.set(scope, attrs, "hash", undefined); // if 'use_lti' is true
315 timHelper.set(scope, attrs, "view_url", undefined);
316316 timHelper.set(scope, attrs, "button", "Tallenna");
317317 //timHelper.set(scope, attrs, "max_grade", 1);
318318 timHelper.set(scope, attrs, "initgrade", "ei pisteitä");
320320 //timHelper.set(scope, attrs, "state.oldgrade", -1);
321321 timHelper.set(scope, attrs, "use_js", true);
322322 timHelper.set(scope, attrs, "use_lti", true);
323 timHelper.set(scope, attrs, "login_url", "https://moodle.jyu.fi/login/jyulogin.php"); // JY Moodlen login page as default
323324 timHelper.set(scope, attrs, "state.tries", 0);
324325 timHelper.set(scope, attrs, "max_tries");
325326 timHelper.setn(scope, "tid", attrs, ".taskID"); // vain kokeilu että "juuresta" ottaminen toimii
382382 }
383383 }
384384 };
385
386 console.log("taskId", $scope.taskId);
387 console.log("params", params);
385388
386389 if (nosave) params.input.nosave = true;
387390 var url = "/lti/answer";
timApp/modules/lti/lti.py
(22 / 11)
  
2828fixed_lti_params = {
2929 'lti_message_type': 'basic-lti-launch-request',
3030 'lti_version': 'LTI-1p0',
31 #'launch_url': "http://timstack.it.jyu.fi:8080/moodle/local/ltiprovider/tool.php?id=8",
31 #'tool_url': "http://timstack.it.jyu.fi:8080/moodle/local/ltiprovider/tool.php?id=8",
3232 'consumer_secret': '__lti_secret__',
3333 'consumer_key': '__consumer_key__',
3434 'resource_link_id': 'tim.jyu.fi',
8989 key = '__consumer_key__'
9090 secret = '__lti_secret__'
9191 tim_id = query.get_param('user_id', 'Query exists but no USER_ID')
92 launch_url = query.get_param('launch_url', 'DEFAULT_launch_url')
92 tool_url = query.get_param('tool_url', 'DEFAULT_tool_url')
9393 view_url = query.get_param('view_url', 'DEFAULT_view_url')
9494 else:
9595 key = '__consumer_key__'
9696 secret = '__lti_secret__'
9797 tim_id = 'Query does not exist: using default ID'
98 launch_url = 'http://timstack.it.jyu.fi' # Should actually be some 404 page...
98 tool_url = 'http://timstack.it.jyu.fi' # Should actually be some 404 page...
9999 view_url = 'http://timstack.it.jyu.fi' # Should actually be some 404 page...
100100
101101 # Get question ID that matches given Moodle question URL
102102 #qid = getQID(question_url)
103103 #qid = question_url
104 qid = launch_url
104 qid = tool_url
105105
106106 LTI_params = fixed_lti_params
107 LTI_params['launch_url'] = launch_url
107 LTI_params['tool_url'] = tool_url
108108 LTI_params['user_id'] = tim_id
109109 LTI_params['lis_person_contact_email_primary'] = tim_id + "@jyu.fi"
110110 LTI_params['lis_person_sourcedid'] = 'PERSONSOURCEDID_' + tim_id
113113 LTI_params['lis_person_name_full'] = 'user_id: ' + tim_id
114114 LTI_params['lis_result_sourcedid'] = tim_id + '_' + qid
115115
116 launch_url = LTI_params['launch_url']
116 tool_url = LTI_params['tool_url']
117117 LTI_credentials = {'consumer_key': key, 'consumer_secret': secret}
118118
119 NewConsumer = Consumer(credentials=LTI_credentials, lti_params=LTI_params, tp_url=launch_url)
119 NewConsumer = Consumer(credentials=LTI_credentials, lti_params=LTI_params, tp_url=tool_url)
120120 return NewConsumer
121121
122122
148148 except KeyError as e:
149149 return self.wout("Did not find any consumer with hash_in_GET: " + hash_in_GET)
150150
151 def do_getlink(self):
152
153 do_headers(self, 'text/html')
154 link = str(get_params(self).get_param('page', "DEFAULT LINK"))
155 page_html = '<script>document.location.href="' + link + '";</script>'
156 return self.wout(page_html)
157
151158 def do_new_consumer(self, query: QueryParams):
152159
153160 self.send_response(303)
208208 + "user_id: <input type=\"text\" name=\"user_id\" value=\"consumeri\" size=\"50\">" \
209209 + "<input type=\"submit\" value=\"New Consumer\"><br>" \
210210 \
211 + "launch_url: <input type=\"text\" name=\"launch_url\" size=\"100\"" \
211 + "tool_url: <input type=\"text\" name=\"tool_url\" size=\"100\"" \
212212 + "value=\"http://timstack.it.jyu.fi:8080/moodle/local/ltiprovider/tool.php?id=1\">" \
213213 \
214214 + "</form>"
294294 if self.path.find('/getform') >= 0:
295295 return self.do_getform()
296296
297 if self.path.find('/getlink') >= 0:
298 return self.do_getlink()
299
297300 if self.path.find('/getconsumers') >= 0:
298301 return self.do_getconsumers()
299302
394394 JSO_from_YAML_without_hyphens = query.to_json(accept_nonhyphen)
395395 AngularJS_directive_name = 'lti-runner' # REMEMBER: Angular.JS treats lti-runner <=> ltiRunner
396396
397 use_lti = query.get_param("use_lti", True)
398
397399 try:
398400 # Create our LTI Consumer (don't authorize yet!)
399401 New_Consumer = CreateConsumer(query)
406406 List_of_Consumers.update(consumer_hash_dict)
407407
408408 # Store New_Consumer data into global users dict under the question id (qid)
409 qid = JSO_from_YAML_without_hyphens['markup']['launch_url']
409 #qid = JSO_from_YAML_without_hyphens['markup']['tool_url']
410 qid = query.get_param('tool_url', '')
410411 users[user_id] = users.get(user_id) or {}
411412 users[user_id][qid] = users[user_id].get(qid) or {}
412413 users[user_id][qid] = [{'hash': consumer_hash, 'consumer': New_Consumer, 'grade': None}]
510510 self.wout(sresult)
511511
512512 print(sresult)
513
514 print("==== end of do_answer ====")
515513
516514
517515if __name__ == '__main__':