Commit b4212375a40d5ab6c22fc5d147132c06cb0aab3a

  • avatar
  • vesal (Committer)
  • Sun Nov 12 03:04:59 EET 2017
  • avatar
  • vesal (Author)
  • Sun Nov 12 03:04:59 EET 2017
csPlugin ping, MD can ave pre and post texts
timApp/modules/cs/js/csPlugin.ts
(39 / 17)
  
171171 file: {};
172172 postcode: string;
173173 precode: string;
174 showCodeLocal();
174 getCodeFromLocalCode(f);
175175 getReplacedCode(): string;
176176 replace: string;
177177 code: string;
309309 copyTauno(): void;
310310 showOtherEditor(editorMode: number): void;
311311 showCodeNow(): void;
312 getAllCode(f): void;
312313 aceLoaded(ace: IAce, editor: IAceEditor): void;
313314 $evalAsync(param: () => any): void;
314315}
520520// What are known language types (be carefull not to include partial word):
521521languageTypes.runTypes = ["css","jypeli","scala","java","graphics","cc","c++","shell","vpython","py","fs","clisp",
522522 "jjs","psql","sql","alloy","text","cs","run","md","js","glowscript","sage","simcir",
523 "xml", "octave","lua", "swift","mathcheck", "html", "processing", "r", "wescheme"];
523 "xml", "octave","lua", "swift","mathcheck", "html", "processing", "r", "wescheme", "ping"];
524524languageTypes.aceModes = ["css","csharp","scala","java","java" ,"c_cpp","c_cpp","sh","python","python","fsharp","lisp",
525 "javascript","sql","sql","alloy","text","csharp","run","markdown","javascript","javascript","python","json",
526 "xml","octave","lua","swift","text", "html", "javascript", "r", "scheme"];
525 "javascript","sql","sql","alloy","text","csharp","run","text","javascript","javascript","python","json",
526 "xml","octave","lua","swift","text", "html", "javascript", "r", "scheme", "text"];
527527// For editor modes see: http://ace.c9.io/build/kitchen-sink.html ja sieltä http://ace.c9.io/build/demo/kitchen-sink/demo.js
528528
529529// What are known test types (be carefull not to include partial word):
571571};
572572
573573languageTypes.getAceModeType = function(type,def) {
574
574 if ( def ) return def;
575575 return this.whatIsInAce(this.runTypes,type,def);
576576};
577577
999999 csApp.set(scope,attrs,"validityCheck","");
10001000 csApp.set(scope,attrs,"validityCheckMessage","");
10011001 csApp.set(scope,attrs,"savestate");
1002 csApp.set(scope,attrs,"mode");
10021003
10031004 csApp.set(scope,attrs,"wrap", scope.isText ? 70 : -1);
10041005 scope.wrap = {n:scope.wrap}; // to avoid child scope problems
11151115 if ( scope.attrs.autorun ) scope.runCodeLink(true);
11161116 scope.editorIndex = 0;
11171117 if ( scope.editorMode != 0 || scope.editorModes !== "01" || scope.cssPrint) scope.showOtherEditor(scope.editorMode); //Forces code editor to change to pre
1118 scope.mode = languageTypes.getAceModeType(scope.type,"");
1118 scope.mode = languageTypes.getAceModeType(scope.type, scope.mode);
11191119
11201120 var styleArgs = csApp.getParam(scope,"style-args","");
11211121 if ( styleArgs ) {
22112211 return $scope.code;
22122212 }
22132213
2214 $scope.showCodeLocal = function() {
2214 $scope.getCodeFromLocalCode = function(f) {
2215 // f: function to call after ready
22152216 // $scope.code = $scope.localcode;
2216 if ( $scope.localcode === "" ) { $scope.code = $scope.usercode; return; }
2217 if ( $scope.localcode === "" ) {
2218 $scope.code = $scope.usercode;
2219 $scope.precode = "";
2220 $scope.postcode = "";
2221 if (f) f();
2222 return;
2223 }
22172224 var st = $scope.localcode.split("\n");
22182225 var r = "";
22192226 var rp = ["",""]; // alkuosa, loppuosa
22442244 $scope.code = r;
22452245 $scope.precode = rp[0];
22462246 $scope.postcode = rp[1];
2247 if (f) f();
22472248 };
22482249
2249
22502250 $scope.showCodeNow = function() {
2251 if (!$scope.viewCode) return;
2252 $scope.getAllCode(null);
2253 }
2254
2255 $scope.getAllCode = function(f) {
2256 // f: function to call after ready
22512257 // var copyEvent = new ClipboardEvent('copy', { dataType: 'text/plain', data: 'kissa' } );
22522258 // document.dispatchEvent(copyEvent);
2253 if ( !$scope.viewCode ) return;
2254 if ( angular.isDefined($scope.localcode) ) { $scope.showCodeLocal(); return; }
2255 if ( !$scope.file &&!$scope.attrs.program ) { $scope.localcode = ""; $scope.showCodeLocal(); return; }
2259 if ( angular.isDefined($scope.localcode) ) { $scope.getCodeFromLocalCode(f); return; }
2260 if ( !$scope.file &&!$scope.attrs.program ) { $scope.localcode = ""; $scope.getCodeFromLocalCode(f); return; }
22562261
22572262 // params = 'print=1&type='+encodeURIComponent($scope.type)+'&file='+encodeURIComponent($scope.file)+ '&keplace='+ encodeURIComponent($scope.replace)+ '&by=' + encodeURIComponent($scope.usercode);
22582263 var params = $scope.attrs;
22702270 // Server always seems to give text/plain as result, so prepare for it.
22712271 if (typeof data === "string") {
22722272 $scope.localcode = data;
2273 $scope.showCodeLocal();
2273 $scope.getCodeFromLocalCode(f);
22742274 }
22752275 else if (data.msg !== '')
22762276 {
22772277 $scope.localcode = data.msg;
2278 $scope.showCodeLocal();
2278 $scope.getCodeFromLocalCode(f);
22792279 }
22802280 else
22812281 {
22822282 $scope.errors.push(data.error);
2283 $scope.precode = "";
2284 $scope.postcode = "";
22832285 }
22842286 }, function(response) {
22852287 let status = response.status;
22862288 $scope.errors.push(status);
2289 $scope.precode = "";
2290 $scope.postcode = "";
22872291 });
22882292 };
22892293
22952295
22962296 $scope.showMD = function() {
22972297 if ( !$scope.usercode ) return;
2298 var text = $scope.usercode.replace($scope.cursor,"");
2298 if ( $scope.precode === undefined ) {
2299 $scope.getAllCode($scope.showMD);
2300 return;
2301 }
2302 var text = $scope.precode + "\n" + $scope.usercode.replace($scope.cursor,"") + "\n" + $scope.postcode;
22992303 if ( text == $scope.lastMD ) return;
23002304 $scope.lastMD = text;
23012305 $scope.previewUrl="/preview/" + $scope.taskId.split(".")[0]; // 12971"
24852485 else
24862486 html = [editorHtml,aceHtml,parsonsHtml,parsonsHtml];
24872487
2488 $scope.mode = languageTypes.getAceModeType($scope.type,"");
2488 $scope.mode = languageTypes.getAceModeType($scope.type,$scope.mode);
24892489 if (typeof editorMode !== 'undefined') $scope.editorMode = editorMode;
24902490 else $scope.editorMode++;
24912491 if ( $scope.editorMode >= $scope.editorModeIndecies.length-1 ) $scope.editorMode = 0;
25882588 $scope.getCode = function() {
25892589 if ( $scope.attrs.program && !$scope.codeInitialized ) {
25902590 $scope.localcode = $scope.attrs.program;
2591 $scope.showCodeLocal();
2591 $scope.getCodeFromLocalCode(null);
25922592 }
25932593 $scope.codeInitialized = true;
25942594 var text = $scope.usercode.replace($scope.cursor,"");
timApp/modules/cs/languages.py
(6 / 0)
  
313313 return code, out, err, pwddir
314314
315315
316class Ping(Shell):
317 def run(self, web, sourcelines, points_rule):
318 return 0, "Ping", "", ""
319
320
316321class Java(Language):
317322 def __init__(self, query, sourcecode):
318323 super().__init__(query, sourcecode)
923923languages["octave"] = Octave
924924languages["processing"] = Processing
925925languages["wescheme"] = WeScheme
926languages["ping"] = Ping