app.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. var ivProgApp = angular.module('ivprog', ['ivprogServices', 'ui']);
  2. var cacheTime = 4; //new Date().getTime(); //2;//new Date().getTime(); // change to string empty to production
  3. var lang = 'pt';
  4. ivProgApp.config(['$routeProvider', function($routeProvider) {
  5. $routeProvider.
  6. when('/startup', { templateUrl: 'partials/start.html', controller: StartCtrl }).
  7. when('/opened/:exercicioId', { templateUrl: 'partials/opened.html', controller: IvProgAbertoCtrl }).
  8. when('/create/',
  9. {
  10. templateUrl: 'partials/create.html'+"?t="+cacheTime,
  11. controller: IvProgCreateCtrl
  12. }).
  13. otherwise({redirectTo: '/create'}); // era startup
  14. }
  15. ]);
  16. ivProgApp.run(function($rootScope){
  17. trackAction("opened");
  18. $rootScope.showBack = false;
  19. // alert('lang=' + iLMparameters.lang + ', sendAnswer=' + iLMparameters.iLM_PARAM_SendAnswer);
  20. // Look the presence of parameter '&lang='
  21. if (iLMparameters.lang!=null) {
  22. if (iLMparameters.lang=='pt_br' || iLMparameters.lang=='pt_BR') lang = 'pt';
  23. else lang = iLMparameters.lang;
  24. $rootScope.currentLanguage = lang;
  25. }
  26. else $rootScope.currentLanguage = 'pt';
  27. //D alert('lang=' + iLMparameters.lang + '=' + $rootScope.currentLanguage);
  28. // loading JSDeferred
  29. Deferred.define();
  30. if (iLMparameters.iLM_PARAM_SendAnswer=="false") {
  31. $("#caseTests").show();
  32. $("#btnTest").show();
  33. $rootScope.notSend = false;
  34. }else{ // default is to allow to send...
  35. $("#caseTests").hide();
  36. $("#btnTest").hide();
  37. $rootScope.notSend = true;
  38. }
  39. });
  40. ivProgApp.directive('editInPlace', function() {
  41. return {
  42. restrict: 'A',
  43. scope: { value: '=editInPlace' },
  44. template: '<span ng-click="edit()" ng-bind="value" class="normal editable"></span><span class="control-group"><input ng-model="value" type="text" class="input" /></span>',
  45. link: function ( $scope, element, attrs ) {
  46. // Let's get a reference to the input element, as we'll want to reference it.
  47. //var inputElement = angular.element( element.children()[1] );
  48. var inputElement = $(element).find("input");
  49. var spanControlGroup = $(element).find(".control-group");
  50. // This directive should have a set class so we can style it.
  51. element.addClass('edit-in-place');
  52. // Initially, we're not editing.
  53. $scope.editing = false;
  54. // ng-click handler to activate edit-in-place
  55. $scope.edit = function () {
  56. $scope.editing = true;
  57. // We control display through a class on the directive itself. See the CSS.
  58. element.addClass( 'active' );
  59. // And we must focus the element.
  60. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  61. // we have to reference the first element in the array.
  62. inputElement[0].focus();
  63. };
  64. $(element).mouseout(function(){
  65. $(this).removeClass("over");
  66. });
  67. $(element).mouseover(function(){
  68. $(this).addClass("over");
  69. });
  70. $(inputElement).keyup(function(e){
  71. if(e.keyCode==13){
  72. if($scope.isValid($scope.value)){
  73. $scope.editing = false;
  74. element.removeClass('active');
  75. element.removeClass('over');
  76. $(spanControlGroup).removeClass("error");
  77. }else{
  78. $(spanControlGroup).addClass("error");
  79. }
  80. }
  81. });
  82. // When we leave the input, we're done editing.
  83. $(inputElement).blur(function(){
  84. if($scope.isValid($scope.value)){
  85. $scope.editing = false;
  86. element.removeClass('active');
  87. $(spanControlGroup).removeClass("error");
  88. }else{
  89. $(spanControlGroup).addClass("error");
  90. }
  91. });
  92. //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  93. $scope.isValid = function(value){
  94. return true;
  95. var VAR_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  96. return VAR_NAME.test(value);
  97. }
  98. }
  99. };
  100. });
  101. ivProgApp.directive('editInPlaceVarValue', function($rootScope) {
  102. return {
  103. restrict: 'A',
  104. scope: {
  105. value: '=editInPlaceVarValue',
  106. type: '=type'
  107. },
  108. templateUrl: 'partials/directives/edit-in-place-var-values.html'+"?t="+cacheTime,
  109. link: function ( $scope, element, attrs ) {
  110. // Let's get a reference to the input element, as we'll want to reference it.
  111. //var inputElement = angular.element( element.children()[1] );
  112. var inputElement = $(element).find("input");
  113. var spanControlGroup = $(element).find(".control-group");
  114. // This directive should have a set class so we can style it.
  115. element.addClass('edit-in-place');
  116. // Initially, we're not editing.
  117. $scope.editing = false;
  118. $scope.getValue = function(){
  119. if($scope.value==""){
  120. return "====";
  121. }else{
  122. return $scope.value;
  123. }
  124. }
  125. // ng-click handler to activate edit-in-place
  126. $scope.edit = function () {
  127. if($scope.type=="boolean"){
  128. $scope.value = !$scope.value;
  129. }else{
  130. $scope.editing = true;
  131. // We control display through a class on the directive itself. See the CSS.
  132. element.addClass( 'active' );
  133. // And we must focus the element.
  134. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  135. // we have to reference the first element in the array.
  136. inputElement[0].focus();
  137. }
  138. }
  139. $(element).mouseout(function(){
  140. $(this).removeClass("over");
  141. });
  142. $(element).mouseover(function(){
  143. $(this).addClass("over");
  144. });
  145. $(inputElement).keyup(function(e){
  146. if(e.keyCode==13){
  147. if($scope.isValid($scope.value)){
  148. $scope.editing = false;
  149. element.removeClass('active');
  150. element.removeClass('over');
  151. $(spanControlGroup).removeClass("has-error");
  152. }else{
  153. $(spanControlGroup).addClass("has-error");
  154. }
  155. }
  156. });
  157. // When we leave the input, we're done editing.
  158. $(inputElement).blur(function(){
  159. if($scope.isValid($scope.value)){
  160. $scope.editing = false;
  161. element.removeClass('active');
  162. $(spanControlGroup).removeClass("has-error");
  163. }else{
  164. $(spanControlGroup).addClass("has-error");
  165. }
  166. });
  167. //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  168. $scope.isValid = function(value){
  169. //return true;
  170. if($scope.type=="int"){
  171. var VAR_NAME = /^[0-9]*$/;
  172. return VAR_NAME.test(value);
  173. }
  174. if($scope.type=="float"){
  175. var VAR_NAME = /^[\-+]?[0-9]*\.?[0-9]*$/;
  176. return VAR_NAME.test(value);
  177. }
  178. return true;
  179. }
  180. }
  181. };
  182. });
  183. ivProgApp.directive('varValue', function($rootScope) {
  184. return {
  185. restrict: 'A',
  186. scope: {
  187. value: '=varValue',
  188. vars: '=vars',
  189. ttype: '=ttype',
  190. type: '=type'
  191. },
  192. templateUrl: 'partials/directives/var-value.html'+"?t="+cacheTime,
  193. link: function ( $scope, element, attrs ) {
  194. $scope.alternate = function(){
  195. if($scope.ttype=="var"){
  196. $scope.ttype = "val";
  197. $scope.value = 5;
  198. }else{
  199. $scope.ttype = "var";
  200. $scope.value = '';
  201. }
  202. }
  203. }
  204. };
  205. });
  206. ivProgApp.directive('editExpression', function() {
  207. return {
  208. restrict: 'A',
  209. scope: {
  210. ex: '=editExpression',
  211. type: '=type',
  212. vars: '=vars'
  213. },
  214. templateUrl: 'partials/directives/edit-expression.html'+"?t="+cacheTime,
  215. link: function ( $scope, element, attrs ) {
  216. // Let's get a reference to the input element, as we'll want to reference it.
  217. //var inputElement = angular.element( element.children()[1] );
  218. /*var inputElement = $(element).find("input");
  219. var spanControlGroup = $(element).find(".control-group");
  220. // This directive should have a set class so we can style it.
  221. element.addClass('edit-in-place');
  222. // Initially, we're not editing.
  223. $scope.editing = false;
  224. // ng-click handler to activate edit-in-place
  225. $scope.edit = function () {
  226. if($scope.type=="boolean"){
  227. $scope.value = !$scope.value;
  228. }else{
  229. $scope.editing = true;
  230. // We control display through a class on the directive itself. See the CSS.
  231. element.addClass( 'active' );
  232. // And we must focus the element.
  233. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  234. // we have to reference the first element in the array.
  235. inputElement[0].focus();
  236. }
  237. }
  238. $(element).mouseout(function(){
  239. $(this).removeClass("over");
  240. });
  241. $(element).mouseover(function(){
  242. $(this).addClass("over");
  243. });
  244. $(inputElement).keyup(function(e){
  245. if(e.keyCode==13){
  246. if($scope.isValid($scope.value)){
  247. $scope.editing = false;
  248. element.removeClass('active');
  249. element.removeClass('over');
  250. $(spanControlGroup).removeClass("has-error");
  251. }else{
  252. $(spanControlGroup).addClass("has-error");
  253. }
  254. }
  255. });
  256. // When we leave the input, we're done editing.
  257. $(inputElement).blur(function(){
  258. if($scope.isValid($scope.value)){
  259. $scope.editing = false;
  260. element.removeClass('active');
  261. $(spanControlGroup).removeClass("has-error");
  262. }else{
  263. $(spanControlGroup).addClass("has-error");
  264. }
  265. });
  266. //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  267. $scope.isValid = function(value){
  268. //return true;
  269. if($scope.type=="int"){
  270. var VAR_NAME = /^[0-9]*$/;
  271. return VAR_NAME.test(value);
  272. }
  273. if($scope.type=="float"){
  274. var VAR_NAME = /^[\-+]?[0-9]*\.?[0-9]*$/;
  275. return VAR_NAME.test(value);
  276. }
  277. return true;
  278. }*/
  279. }
  280. };
  281. });
  282. ivProgApp.directive('editExpressionJava', function() {
  283. return {
  284. restrict: 'A',
  285. scope: {
  286. ex: '=editExpressionJava',
  287. type: '=type',
  288. vars: '=vars'
  289. },
  290. templateUrl: 'partials/directives/edit-expression-java.html'+"?t="+cacheTime,
  291. link: function ( $scope, element, attrs ) {
  292. // Let's get a reference to the input element, as we'll want to reference it.
  293. $scope.setType = function(item, type){
  294. item.t = type;
  295. if(type=='val'){
  296. item.v = $scope.getDefaultValue();
  297. }
  298. }
  299. $scope.addEl = function(p, type){
  300. if(type=="val"){
  301. if($scope.type=="int"){
  302. p.push({ t: type, v: 1 });
  303. }else if($scope.type=="float"){
  304. p.push({ t: type, v: 1.0 });
  305. }else if($scope.type=="boolean"){
  306. p.push({
  307. t: 'expB',
  308. v: [
  309. { t: 'var', v: '' },
  310. { t: 'opB', v: '' },
  311. { t: '', v: '' }
  312. ]});
  313. //p.push({ t: type, v: false });
  314. }else if($scope.type=="string"){
  315. p.push({ t: type, v: 'texto' });
  316. }else{
  317. p.push({ t: type, v: ''});
  318. }
  319. }else if(type=="var"){
  320. p.push({ t: type, v: ''});
  321. }
  322. }
  323. $scope.getDefaultValue = function(){
  324. if($scope.type=="int"){
  325. return 1;
  326. }else if($scope.type=="float"){
  327. return 1.0;
  328. }else if($scope.type=="boolean"){
  329. return false;
  330. }else if($scope.type=="string"){
  331. return 'texto';
  332. }else{
  333. return '';
  334. }
  335. }
  336. $scope.selectOp = function(opParent, op){
  337. //$scope.ex.push({ t: 'op', v: op});
  338. var old = angular.copy(opParent);
  339. opParent.v = [];
  340. opParent.t = "exp";
  341. opParent.v.push(old);
  342. opParent.v.push({t: 'op', v: op});
  343. }
  344. $scope.cleanOp = function(item){
  345. item.t = "";
  346. item.v = "";
  347. }
  348. $scope.operators = {
  349. "+": {
  350. id: "+",
  351. display: "Adição",
  352. compatible: ["float", "int", "string"]
  353. },
  354. "-": {
  355. id: "-",
  356. display: "Subtração",
  357. compatible: ["float", "int"]
  358. },
  359. "/": {
  360. id: "/",
  361. display: "Divisão",
  362. compatible: ["float", "int"]
  363. },
  364. "*": {
  365. id: "*",
  366. display: "Multiplicação",
  367. compatible: ["float", "int"]
  368. },
  369. "%": {
  370. id: "%",
  371. display: "Resto da divisão",
  372. compatible: ["float", "int"]
  373. },
  374. "&&": {
  375. id: "&&",
  376. display: "E",
  377. compatible: ["boolean"]
  378. },
  379. "||": {
  380. id: "||",
  381. display: "OU",
  382. compatible: ["boolean"]
  383. }
  384. };
  385. }
  386. };
  387. });
  388. ivProgApp.directive('editExpressionJavaReadOnly', function() {
  389. return {
  390. restrict: 'A',
  391. scope: {
  392. ex: '=editExpressionJavaReadOnly',
  393. type: '=type',
  394. vars: '=vars'
  395. },
  396. templateUrl: 'partials/directives/edit-expression-java-read-only.html'+"?t="+cacheTime,
  397. link: function ( $scope, element, attrs ) {
  398. $scope.operators = {
  399. "<=": {
  400. id: "<=",
  401. display: "≤",
  402. compatible: ["float", "int"]
  403. },
  404. "<": {
  405. id: "<",
  406. display: "<",
  407. compatible: ["float", "int", "string"]
  408. },
  409. "==": {
  410. id: "==",
  411. display: "==",
  412. compatible: ["float", "int", "string", "boolean"]
  413. },
  414. "!=": {
  415. id: "!=",
  416. display: "≠",
  417. compatible: ["float", "int", "string", "boolean"]
  418. },
  419. ">=": {
  420. id: ">=",
  421. display: "≥",
  422. compatible: ["float", "int"]
  423. },
  424. ">": {
  425. id: ">",
  426. display: ">",
  427. compatible: ["float", "int", "string"]
  428. }
  429. };
  430. $scope.operators2 = {
  431. "+": {
  432. id: "+",
  433. display: "Adição",
  434. compatible: ["float", "int", "string"]
  435. },
  436. "-": {
  437. id: "-",
  438. display: "Subtração",
  439. compatible: ["float", "int"]
  440. },
  441. "/": {
  442. id: "/",
  443. display: "Divisão",
  444. compatible: ["float", "int"]
  445. },
  446. "*": {
  447. id: "*",
  448. display: "Multiplicação",
  449. compatible: ["float", "int"]
  450. },
  451. "%": {
  452. id: "%",
  453. display: "Resto da divisão",
  454. compatible: ["float", "int"]
  455. },
  456. "&&": {
  457. id: "&&",
  458. display: "E",
  459. compatible: ["boolean"]
  460. },
  461. "||": {
  462. id: "||",
  463. display: "OU",
  464. compatible: ["boolean"]
  465. }
  466. };
  467. }
  468. };
  469. });
  470. ivProgApp.directive('editInPlaceVarName', function() {
  471. return {
  472. restrict: 'A',
  473. scope: { value: '=editInPlaceVarName' },
  474. template: '<span ng-click="edit()" ng-bind="value" class="normal"></span><span class="control-group form-group"><input ng-model="value" type="text" class="input-edit input form-control input-sm" /></span>',
  475. link: function ( $scope, element, attrs ) {
  476. // Let's get a reference to the input element, as we'll want to reference it.
  477. var inputElement = $(element).find("input");
  478. var spanControlGroup = $(element).find(".control-group");
  479. // This directive should have a set class so we can style it.
  480. element.addClass('edit-in-place');
  481. // Initially, we're not editing.
  482. $scope.editing = false;
  483. // ng-click handler to activate edit-in-place
  484. $scope.edit = function () {
  485. $scope.editing = true;
  486. // We control display through a class on the directive itself. See the CSS.
  487. element.addClass( 'active' );
  488. // And we must focus the element.
  489. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  490. // we have to reference the first element in the array.
  491. inputElement[0].focus();
  492. };
  493. $(element).mouseout(function(){
  494. $(this).removeClass("over");
  495. });
  496. $(element).mouseover(function(){
  497. $(this).addClass("over");
  498. });
  499. $(inputElement).keyup(function(e){
  500. if(e.keyCode==13){
  501. if($scope.isValid($scope.value)){
  502. $scope.editing = false;
  503. element.removeClass('active');
  504. element.removeClass('over');
  505. $(spanControlGroup).removeClass("has-error");
  506. }else{
  507. $(spanControlGroup).addClass("has-error");
  508. }
  509. }
  510. });
  511. // When we leave the input, we're done editing.
  512. $(inputElement).blur(function(){
  513. if($scope.isValid($scope.value)){
  514. $scope.editing = false;
  515. element.removeClass('active');
  516. $(spanControlGroup).removeClass("has-error");
  517. }else{
  518. $(spanControlGroup).addClass("has-error");
  519. }
  520. });
  521. //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  522. $scope.isValid = function(value){
  523. var VAR_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
  524. return VAR_NAME.test(value);
  525. }
  526. }
  527. };
  528. });
  529. ivProgApp.directive('editInPlaceValue', function() {
  530. return {
  531. restrict: 'A',
  532. scope: { value: '=editInPlaceValue' },
  533. template: '<span ng-click="edit()" ng-bind="value"><span ng-show="value==\'\'">sem valor</span></span><input ng-model="value" type="text" class="input" />',
  534. link: function ( $scope, element, attrs ) {
  535. // Let's get a reference to the input element, as we'll want to reference it.
  536. var inputElement = angular.element( element.children()[1] );
  537. // This directive should have a set class so we can style it.
  538. element.addClass('edit-in-place');
  539. // Initially, we're not editing.
  540. $scope.editing = false;
  541. // ng-click handler to activate edit-in-place
  542. $scope.edit = function () {
  543. $scope.editing = true;
  544. // We control display through a class on the directive itself. See the CSS.
  545. element.addClass( 'active' );
  546. // And we must focus the element.
  547. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  548. // we have to reference the first element in the array.
  549. inputElement[0].focus();
  550. };
  551. $(element).mouseout(function(){
  552. $(this).removeClass("over");
  553. });
  554. $(element).mouseover(function(){
  555. $(this).addClass("over");
  556. });
  557. $(inputElement).keyup(function(e){
  558. if(e.keyCode==13){
  559. $scope.editing = false;
  560. element.removeClass('active');
  561. element.removeClass('over');
  562. }
  563. });
  564. // When we leave the input, we're done editing.
  565. $(inputElement).blur(function(){
  566. $scope.editing = false;
  567. element.removeClass('active');
  568. });
  569. }
  570. };
  571. });
  572. ivProgApp.directive('selectVariable', function() {
  573. return {
  574. restrict: 'A',
  575. scope: {
  576. value: '=selectVariable',
  577. vars: '=selectVars',
  578. type: '=type'
  579. },
  580. templateUrl: 'partials/directives/select-variable.html'+"?t="+cacheTime,
  581. link: function ( $scope, element, attrs ) {
  582. // Let's get a reference to the input element, as we'll want to reference it.
  583. var inputElement = angular.element( element.children()[1] );
  584. // This directive should have a set class so we can style it.
  585. //element.addClass('edit-in-place');
  586. // Initially, we're not editing.
  587. $scope.editing = false;
  588. $scope.setValue = function(v){
  589. $scope.value = v;
  590. }
  591. // ng-click handler to activate edit-in-place
  592. $scope.edit = function () {
  593. $scope.editing = true;
  594. // We control display through a class on the directive itself. See the CSS.
  595. element.addClass( 'active' );
  596. // And we must focus the element.
  597. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  598. // we have to reference the first element in the array.
  599. inputElement[0].focus();
  600. };
  601. $(element).mouseout(function(){
  602. $(this).removeClass("over");
  603. });
  604. $(element).mouseover(function(){
  605. $(this).addClass("over");
  606. });
  607. $(inputElement).keyup(function(e){
  608. if(e.keyCode==13){
  609. $scope.editing = false;
  610. element.removeClass('active');
  611. element.removeClass('over');
  612. }
  613. });
  614. // When we leave the input, we're done editing.
  615. $(inputElement).blur(function(){
  616. $scope.editing = false;
  617. element.removeClass('active');
  618. });
  619. }
  620. };
  621. });
  622. ivProgApp.directive('selectOperator', function() {
  623. return {
  624. restrict: 'A',
  625. scope: {
  626. value: '=selectOperator',
  627. model: '=selectModel',
  628. vars: '=selectVars',
  629. type: '=type'
  630. },
  631. templateUrl: 'partials/directives/select-operator.html'+"?t="+cacheTime,
  632. link: function ( $scope, element, attrs ) {
  633. // Let's get a reference to the input element, as we'll want to reference it.
  634. var inputElement = angular.element( element.children()[1] );
  635. // This directive should have a set class so we can style it.
  636. //element.addClass('edit-in-place');
  637. $scope.operators = {
  638. "+": {
  639. id: "+",
  640. display: "+",
  641. compatible: ["float", "int", "string"]
  642. },
  643. "-": {
  644. id: "-",
  645. display: "-",
  646. compatible: ["float", "int"]
  647. },
  648. "/": {
  649. id: "/",
  650. display: "/",
  651. compatible: ["float", "int"]
  652. },
  653. "*": {
  654. id: "*",
  655. display: "*",
  656. compatible: ["float", "int"]
  657. },
  658. "%": {
  659. id: "%",
  660. display: "%",
  661. compatible: ["float", "int"]
  662. },
  663. "&&": {
  664. id: "&&",
  665. display: "E",
  666. compatible: ["boolean"]
  667. },
  668. "||": {
  669. id: "||",
  670. display: "OU",
  671. compatible: ["boolean"]
  672. }
  673. };
  674. // Initially, we're not editing.
  675. $scope.editing = false;
  676. $scope.setValue = function(v){
  677. $scope.value = v.id;
  678. }
  679. // ng-click handler to activate edit-in-place
  680. $scope.edit = function () {
  681. $scope.editing = true;
  682. // We control display through a class on the directive itself. See the CSS.
  683. element.addClass( 'active' );
  684. // And we must focus the element.
  685. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  686. // we have to reference the first element in the array.
  687. inputElement[0].focus();
  688. };
  689. $(element).mouseout(function(){
  690. $(this).removeClass("over");
  691. });
  692. $(element).mouseover(function(){
  693. $(this).addClass("over");
  694. });
  695. $(inputElement).keyup(function(e){
  696. if(e.keyCode==13){
  697. $scope.editing = false;
  698. element.removeClass('active');
  699. element.removeClass('over');
  700. }
  701. });
  702. // When we leave the input, we're done editing.
  703. $(inputElement).blur(function(){
  704. $scope.editing = false;
  705. element.removeClass('active');
  706. });
  707. }
  708. };
  709. });
  710. ivProgApp.directive('selectVariableExpression', function() {
  711. return {
  712. restrict: 'A',
  713. scope: {
  714. value: '=selectVariableExpression',
  715. ex: '=ex',
  716. vars: '=vars',
  717. type: '=type'
  718. },
  719. templateUrl: 'partials/directives/select-variable-expression.html'+"?t="+cacheTime,
  720. link: function ( $scope, element, attrs ) {
  721. // Let's get a reference to the input element, as we'll want to reference it.
  722. var inputElement = angular.element( element.children()[1] );
  723. // This directive should have a set class so we can style it.
  724. //element.addClass('edit-in-place');
  725. // Initially, we're not editing.
  726. $scope.editing = false;
  727. $scope.setValue = function(v){
  728. $scope.value = v;
  729. }
  730. $scope.isolar = function(item){
  731. item.t = "exp";
  732. item.v = "";
  733. item.exp = [];
  734. }
  735. $scope.convertToValue = function(item){
  736. item.t = "val";
  737. item.v = 0;
  738. }
  739. $scope.removeItem = function(v){
  740. v.p.splice(v.p.indexOf(v), 1);
  741. }
  742. $scope.showOnlyForTypeFilter = function(variable){
  743. console.log(variable);
  744. console.log($scope.type);
  745. return variable.type==$scope.type;
  746. }
  747. // ng-click handler to activate edit-in-place
  748. $scope.edit = function () {
  749. $scope.editing = true;
  750. // We control display through a class on the directive itself. See the CSS.
  751. element.addClass( 'active' );
  752. // And we must focus the element.
  753. // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
  754. // we have to reference the first element in the array.
  755. inputElement[0].focus();
  756. };
  757. $(element).mouseout(function(){
  758. $(this).removeClass("over");
  759. });
  760. $(element).mouseover(function(){
  761. $(this).addClass("over");
  762. });
  763. $(inputElement).keyup(function(e){
  764. if(e.keyCode==13){
  765. $scope.editing = false;
  766. element.removeClass('active');
  767. element.removeClass('over');
  768. }
  769. });
  770. // When we leave the input, we're done editing.
  771. $(inputElement).blur(function(){
  772. $scope.editing = false;
  773. element.removeClass('active');
  774. });
  775. }
  776. };
  777. });
  778. ivProgApp.directive('booleanExpression', function() {
  779. return {
  780. restrict: 'A',
  781. scope: {
  782. value: '=booleanExpression',
  783. ex: '=ex',
  784. vars: '=vars'
  785. },
  786. templateUrl: 'partials/directives/boolean-expression.html'+"?t="+cacheTime,
  787. link: function ( $scope, element, attrs ) {
  788. $scope.setValue = function(va, v){
  789. //$scope.value.op = v;
  790. va = v;
  791. }
  792. $scope.isolar = function(item){
  793. item.t = "exp";
  794. item.v = "";
  795. item.exp = [];
  796. }
  797. $scope.convertToValue = function(item){
  798. item.t = "val";
  799. item.v = 0;
  800. }
  801. $scope.removeItem = function(v){
  802. v.p.splice(v.p.indexOf(v), 1);
  803. }
  804. $scope.showOnlyForTypeFilter = function(variable){
  805. return variable.type==$scope.type;
  806. }
  807. $scope.getDefaultValue = function(type){
  808. if(type=="int"){
  809. return 1;
  810. }else if(type=="float"){
  811. return 1.0;
  812. }else if(type=="boolean"){
  813. return false;
  814. }else if(type=="string"){
  815. return 'texto';
  816. }else{
  817. return '';
  818. }
  819. }
  820. $scope.operators = {
  821. "<=": {
  822. id: "<=",
  823. display: "≤",
  824. compatible: ["float", "int"]
  825. },
  826. "<": {
  827. id: "<",
  828. display: "<",
  829. compatible: ["float", "int", "string"]
  830. },
  831. "==": {
  832. id: "==",
  833. display: "==",
  834. compatible: ["float", "int", "string", "boolean"]
  835. },
  836. "!=": {
  837. id: "!=",
  838. display: "≠",
  839. compatible: ["float", "int", "string", "boolean"]
  840. },
  841. ">=": {
  842. id: ">=",
  843. display: "≥",
  844. compatible: ["float", "int"]
  845. },
  846. ">": {
  847. id: ">",
  848. display: ">",
  849. compatible: ["float", "int", "string"]
  850. }
  851. };
  852. }
  853. };
  854. });
  855. ivProgApp.directive('buttons', function($rootScope) {
  856. return {
  857. restrict: 'A',
  858. scope: {
  859. nodes: '=buttons',
  860. idParent: '=idParent'
  861. },
  862. templateUrl: 'partials/directives/buttons.html'+"?t="+cacheTime,
  863. link: function ( $scope, element, attrs ) {
  864. $scope.add = function(parent, parentId, type, name) {
  865. trackAction("add;type="+type);
  866. var newNode = {
  867. id: $rootScope.itemCount++,
  868. type: type,
  869. name: name,
  870. nodes: [],
  871. parent: parentId
  872. };
  873. // especifico de cada estrutura
  874. if(type=="if"){
  875. newNode.exp = [/*
  876. { t: 'expB',
  877. v: [{"t":"val","v":""},{"t":"opB","v":""},{"t":"val","v":""}]
  878. }*/
  879. ];
  880. newNode.isChildrenVisible = true;
  881. newNode.nodes1 = [];
  882. newNode.nodes2 = [];
  883. }
  884. if(type=="read"){
  885. newNode.message = "Por favor digite um valor:";
  886. newNode.variable = "";
  887. }
  888. if(type=="write"){
  889. newNode.variable = "";
  890. }
  891. if(type=="for"){
  892. newNode.forType = 1; // 1 SIMPLE, 2 +-, 3 COMPLETE
  893. newNode.initial = 1;
  894. newNode.initialType = "val";
  895. newNode.limit = 5;
  896. newNode.limitType = "val";
  897. newNode.using = "";
  898. newNode.step = 1;
  899. newNode.stepType = "val";
  900. newNode.isChildrenVisible = true;
  901. newNode.times = 5;
  902. newNode.timesType = 5;
  903. newNode.simple = true;
  904. newNode.isValue = true;
  905. newNode.simpleVariable = "";
  906. newNode.initialValue = 0;
  907. newNode.endValue = 5;
  908. newNode.increment = 1;
  909. newNode.variable = "";
  910. }
  911. if(type=="while"){
  912. newNode.id = "while_"+newNode.id;
  913. newNode.exp = [];
  914. newNode.isChildrenVisible = true;
  915. newNode.nodes = [];
  916. }
  917. if(type=="attr"){
  918. newNode.id = "attr_"+newNode.id;
  919. newNode.variable = "";
  920. //newNode.exp = [];
  921. /*newNode.exp = {
  922. op1: '',
  923. op1T : '',
  924. op: '',
  925. op2: '',
  926. op2T: ''
  927. };*/
  928. delete newNode.nodes;
  929. newNode.exp = [];
  930. newNode.isLocked = false;
  931. }
  932. parent.push(newNode);
  933. $rootScope.mapping[newNode.id] = newNode;
  934. };
  935. }
  936. };
  937. });
  938. var INTEGER_REGEXP = /^\-?\d*$/;
  939. ivProgApp.directive('integer', function() {
  940. return {
  941. require: 'ngModel',
  942. link: function(scope, elm, attrs, ctrl) {
  943. ctrl.$parsers.unshift(function(viewValue) {
  944. if (INTEGER_REGEXP.test(viewValue)) {
  945. // it is valid
  946. ctrl.$setValidity('integer', true);
  947. return viewValue;
  948. } else {
  949. // it is invalid, return undefined (no model update)
  950. ctrl.$setValidity('integer', false);
  951. return undefined;
  952. }
  953. });
  954. }
  955. };
  956. });