utils.service.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * AccessibleBlockly
  3. *
  4. * Copyright 2016 Google Inc.
  5. * https://developers.google.com/blockly/
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the 'License');
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an 'AS IS' BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /**
  20. * @fileoverview Angular2 utility service for multiple components. All
  21. * functions in this service should be stateless, since this is a singleton
  22. * service that is used for the entire application.
  23. *
  24. * @author madeeha@google.com (Madeeha Ghori)
  25. */
  26. var blocklyApp = {};
  27. blocklyApp.UtilsService = ng.core
  28. .Class({
  29. constructor: function() {},
  30. generateUniqueId: function() {
  31. return 'blockly-' + Blockly.genUid();
  32. },
  33. generateIds: function(elementsList) {
  34. var idMap = {};
  35. for (var i = 0; i < elementsList.length; i++){
  36. idMap[elementsList[i]] = this.generateUniqueId();
  37. }
  38. return idMap;
  39. },
  40. generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) {
  41. var attrValue = mainLabel + ' ' + secondLabel;
  42. if (isDisabled) {
  43. attrValue += ' blockly-disabled';
  44. }
  45. return attrValue;
  46. },
  47. getInputTypeLabel: function(connection) {
  48. // Returns an upper case string in the case of official input type names.
  49. // Returns the lower case string 'any' if any official input type qualifies.
  50. // The differentiation between upper and lower case signifies the difference
  51. // between an input type (BOOLEAN, LIST, etc) and the colloquial english term
  52. // 'any'.
  53. if (connection.check_) {
  54. return connection.check_.join(', ').toUpperCase();
  55. } else {
  56. return Blockly.Msg.ANY;
  57. }
  58. },
  59. getBlockTypeLabel: function(inputBlock) {
  60. if (inputBlock.type == Blockly.NEXT_STATEMENT) {
  61. return Blockly.Msg.STATEMENT;
  62. } else {
  63. return Blockly.Msg.VALUE;
  64. }
  65. }
  66. });