1
0

wizard-controller.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. angular.module('SolvIn')
  2. .controller('WizardController', function ($scope, $state, $stateParams, $mdToast, PureBeing, PureNothing, Becoming, Passing, Uprising, ExtantBeing, Nihility, Quality, Something, FluentSomething, Definition, Limit, Quantity, Progress) {
  3. $scope.steps = [];
  4. $scope.stepsMap = {};
  5. var injected = arguments;
  6. function pushSteps(...ids) {
  7. Array.from(ids).forEach(function (id) {
  8. var step = Array.from(injected).find(s => _.isEqual(s.id, id) && _.isArray(s.words));
  9. if (_.isObject(step)) {
  10. $scope.steps.push(step);
  11. $scope.stepsMap[id] = $scope.steps.length - 1;
  12. } else {
  13. console.log(`no step for ${id}`);
  14. }
  15. });
  16. }
  17. pushSteps('PureBeing', 'PureNothing', 'Becoming', 'Passing', 'Uprising', 'ExtantBeing', 'Nihility', 'Quality', 'Something', 'FluentSomething', 'Definition', 'Limit', 'Quantity', 'Progress');
  18. $scope.rotate = function (w) {
  19. return [0, 0, 0, 90, -90][Math.round(4 * Math.random())];
  20. };
  21. let update = $scope.update = function () {
  22. $scope.words = [];
  23. const maxWords = 200;
  24. let step = $scope.step = $scope.steps[$scope.stepIdx];
  25. for(var i = 0; i<maxWords; i++){
  26. $scope.words.push({
  27. name: step.words[Math.round((step.words.length -1) * Math.random())],
  28. score: i < (2 * maxWords / 3) ? Math.random() / 2 : Math.random(),
  29. index: i
  30. })
  31. }
  32. };
  33. $scope.events = {
  34. click: function (tag) {
  35. $mdToast.showSimple('КЛИК')
  36. }
  37. };
  38. $scope.showStep = function (idx){
  39. if(_.isNumber(idx)) {
  40. $scope.stepIdx = idx;
  41. } else {
  42. $scope.stepIdx = $scope.stepsMap[idx];
  43. }
  44. $state.go('wizard', {id: _.invert($scope.stepsMap)[$scope.stepIdx]}, {reload: true});
  45. };
  46. $scope.showNextStep = function () {
  47. $scope.showStep($scope.stepIdx + 1);
  48. };
  49. $scope.showPrevStep = function () {
  50. $scope.showStep($scope.stepIdx - 1);
  51. };
  52. $scope.hasNextStep = function () {
  53. return ($scope.stepIdx + 1) < $scope.steps.length;
  54. };
  55. $scope.hasPrevStep = function () {
  56. return ($scope.stepIdx - 1) >= 0;
  57. };
  58. if (_.isUndefined($stateParams.id)) {
  59. $scope.showStep('PureBeing');
  60. } else {
  61. $scope.stepIdx = $scope.stepsMap[$stateParams.id];
  62. update();
  63. }
  64. });