Esempio n. 1
0
  constructor($scope, $location, $window, $document, Scroll) {
    assign(this, {
      $location, Scroll, $document,
      classnames: {},
      currentRouteName: undefined,
    });

    $scope.$on('$locationChangeStart', (e, n) => this.updateContentClass(e, n));
    $scope.$on('content-classname', (e, n) => this.updateContentClass(e, n));
    this.updateContentClass();

    Scroll.addListener(() => this.scrollListener());
  }
Esempio n. 2
0
 constructor($scope, Restangular, User) {
   assign(this, {
     Restangular,
     $scope,
     UserService: User,
     user: User.details,
     facts: User.facts,
     fields: User.fields,
     courses: User.courses,
     thesisinput: !!(User.details.thesis_title || User.details.thesis_grade),
   });
   // Forces a $scope.$apply when relevant user data changes out-of-cycle.
   User.addWatcher(() => this.apply());
 }
Esempio n. 3
0
  constructor($location, $routeParams, Restangular, User) {
    const d = new Date(),
      m = d.getMonth(),
      y = d.getFullYear();
    assign(this, {
      $location,
      User,
      course: {},
      page: $routeParams.student_in_course_id ? 'edit' : 'new',
      currentTermYear: m > 3 ? y : y - 1,
      currentTerm: m > 8 || m < 3 ? 'W' : 'S',
    });

    this.fields = Restangular.all('fields').getList({
      regulation_id: User.details.regulation_id,
    }).$object;

    if (this.page === 'edit') {
      // edit course
      const id = parseInt($routeParams.student_in_course_id, 10);
      User.details.one('courses', id).get().then(
        c => {
          // No edits allowed for official courses yet.
          if (c.course_id) {
            $location.path('/~/courses/new');
            return;
          }
          this.course = c;
        },
        () => {
          // Course does not exist, redirect.
          $location.path('/~/courses/new');
        },
      );
    } else {
      // new course
      const fieldId = $routeParams.field_id
        ? parseInt($routeParams.field_id, 10)
        : 1;
      this.course = {
        enrolled_field_id: fieldId,
        year: this.currentTermYear,
        term: this.currentTerm,
      };
    }
  }
Esempio n. 4
0
  // TODO: split into instance methods and controller as style
  constructor($scope, $attrs, $parse, DropdownService, $animate) {
    const self = this;
    assign(this, {
      $attrs,
      $scope,
      $parse,
      scope: $scope.$new(),
      getIsOpen: undefined,
      setIsOpen: () => {},
    });
    const openClass = 'open';
    const toggleInvoker = $attrs.onToggle ? $parse($attrs.onToggle) : () => {};

    this.scope.getToggleElement = () => this.toggleElement;

    this.scope.focusToggleElement = () => {
      if (this.toggleElement) {
        this.toggleElement[0].focus();
      }
    };

    this.scope.$watch('isOpen', (isOpen, wasOpen) => {
      $animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass);

      if (isOpen) {
        this.scope.focusToggleElement();
        DropdownService.open(this.scope);
      } else {
        DropdownService.close(this.scope);
      }

      this.setIsOpen(this.$scope, isOpen);
      if (!isUndefined(isOpen) && isOpen !== wasOpen) {
        toggleInvoker($scope, { open: !!isOpen });
      }
    });

    this.$scope.$on('$locationChangeSuccess', () => {
      this.scope.isOpen = false;
    });

    this.$scope.$on('$destroy', () => {
      this.scope.$destroy();
    });
  }
Esempio n. 5
0
  $onInit() {
    const year = new Date().getFullYear();
    const filteredIds = [];
    let hideLoader;
    let filteredSelectedKey = 0;
    let mouseTimeout;

    assign(this, {
      courses: [],
      states: { mouse: false, input: false, timer: null },
      prefixI: 0,
      prefixes: shuffle(NavbarController.prefixes),
      upperYear: year + 1,
      lowerYear: year - 1,
      fetching: false,
      search: {
        query: '',
        filtered: [],
        limit: 4,
        filter: {},
        selected: null,
        placeholder: 'Quick search',
      },
      navExpanded: false,
      user: false,
    });

    this.$scope.$on('user-construct', (e, user) => this.userConstruct(user));
    // userConstruct(null, User.details);

    // Close dropdown navigation on mobile devices when changing route.
    this.$rootScope.$on('$routeChangeSuccess', () => {
      this.navExpanded = false;
    });

    // Watch the loading variable to show or hide the loading animation.
    this.$rootScope.$watch('loading', n => {
      if (n > 0) {
        this.$timeout.cancel(hideLoader);
        this.showLoader = true;
      } else if (n < 0) {
        this.$rootScope.loading = 0;
      } else {
        hideLoader = this.$timeout(() => {
          this.showLoader = false;
        }, 1100);
      }
    });

    // Watch the quick search input field for changes.
    this.$scope.$watch(
      () => this.search.query,
      (query, oldQuery) => {
        if (query === oldQuery) {
          return;
        }

        const match = query.match(/^([ws])?s?(\d{2,4})?:? (.*)$/i);
        if (match) {
          this.search.filter = pickBy({
            term: isEmpty(match[1]) ? '' : match[1].toUpperCase(),
            year: isEmpty(match[2]) ? '' : `20${match[2]}`.slice(-4),
            course: trim(match[3]),
          });
        } else {
          // this is just a backup if the regex above fails
          this.search.filter = { course: query };
        }

        this.applyFilter();
      },
    );

    // Watch the focus property of the input field.
    this.$scope.$watch(
      () => this.search.focus,
      focused => {
        if (focused === false) {
          this.searchBoxToggle('blur');
        } else if (focused) {
          filteredSelectedKey = 0;
          this.search.selected = filteredIds[filteredSelectedKey];

          if (!this.search.active) {
            this.applyFilter();
          }

          this.searchBoxToggle('focus');
        }
      },
      true,
    );

    // Watch the hover property of the navbar/quick search results.
    // The timeout is required because moving the mouse inline the
    // "area-to-be-hovered" also often triggers this event.
    this.$scope.$watch(
      () => this.search.hover,
      hovering => {
        this.$timeout.cancel(mouseTimeout);
        mouseTimeout = this.$timeout(() => {
          if (hovering === false) {
            this.searchBoxToggle('mouseout');
            return;
          }

          this.searchBoxToggle('mouseover');
        }, 200);
      },
      true,
    );
  }
  toString,
  toUpper,
  trim,
  trimEnd,
  trimStart,
  truncate,
  unescape,
  uniqueId,
  upperCase,
  upperFirst,
  each,
  eachRight,
  first,
} from "lodash-es";

(assign(): {});
(assignIn(): {});
(assignWith(): {});
(at(): Array<*>);
(bindAll(): void);
(bindKey(): Function);
(castArray(): Array<*>);
(chain(null): null);
(chunk(null, null): Array<*>);
(compact(null): Array<*>);
(concat(): Array<*>);
(cond(null): Function);
(conforms(null): Function);
(constant(null): Function);
(countBy(null, null): {});
(create(null, null): {});