wizard-controller.js 2.3 KB

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