<commit_before>import angular from 'angular';

// import services for this modules

//import moment from 'moment';
import EventService from '../../../../services/event/event.service';
import momentPicker from 'angular-moment-picker';
import moment from 'moment';

//import DatetimePickerComponent from '../../../common/datetime-picker/datetime-picker-config';

// imports for this component
import AddressSearchComponent from '../../../address-search/address-search';
import template from './promote-idea.html';
import './promote-idea.css';

class PromoteIdeaController {
  constructor(EventService, $stateParams, $state) {
    this.EventService = EventService;
    this.$stateParams = $stateParams;
    this.$state = $state;
    this.moment = moment;
    this.$onInit = this.$onInit.bind(this);
    this.formWarning = '';
    this.formattedStartTime = '';
    this.formattedEndTime = '';
    this.addressText = '';
    this.addressLink = '';
    this.onEndDateChange = this.onEndDateChange.bind(this);
    this.onStartDateChange = this.onStartDateChange.bind(this);
  }

  $onInit() {
    this.event = this.EventService.getEvent(this.$stateParams.eventId);
    if (!this.event.startTime) {
      this.event.startTime = this.moment().format('MM/DD/YYYY hh:mm A');
    }
    this.formattedStartTime = this.moment(this.event.startTime).format('MM/DD/YYYY hh:mm A');
    if (!this.event.endTime) {
      this.event.endTime = this.moment().format('MM/DD/YYYY hh:mm A');
    }
    this.formattedEndTime = this.moment(this.event.endTime).format('MM/DD/YYYY hh:mm A');
  }

  onStartDateChange(newValue) {
    this.formattedStartTime = newValue.format('MM/DD/YYYY hh:mm A');
  }

  onEndDateChange(newValue) {
    this.formattedEndTime = newValue.format('MM/DD/YYYY hh:mm A');
  }

  findLocation() {
    this.AddressService.findLocation();
  }

  submit() {
    if (this.validateForm()) {
      let promotedIdea = this.event;
      promotedIdea.startTime = new Date(promotedIdea.startTime);
      promotedIdea.endTime = new Date(promotedIdea.endTime);
      promotedIdea.addressText = this.addressText;
      promotedIdea.addressLink = this.addressLink;
      console.log(promotedIdea);
      this.EventService.promoteEvent(promotedIdea).then(resp => {
        this.$state.go('app.plan.planner.ideas');
      }).catch(err => {
        console.log('Server error: ', err);
        this.formWarning = 'Error: please try again or contact a server admin';
      });
    }
  }

  //todo: add calendar limit for end time after start time.

  validateForm() {
    if (!this.event.title) {
      this.formWarning = 'Please enter a title';
    }
    if (!this.event.startTime) {
      this.formWarning = 'Please enter a start time';
      return false;
    }
    if (!this.event.endTime) {
      this.formWarning = 'Please enter an end time';
      return false;
    }
    return true;
  }

  findLocation() {
    this.AddressService.findLocation((src) => {
      let img = new Image();
      img.src = src;
      document.getElementById('address').appendChild(img);
    });
  }
}<commit_msg>Clean up<commit_after>import angular from 'angular';

// import services for this modules

//import moment from 'moment';
import EventService from '../../../../services/event/event.service';
import momentPicker from 'angular-moment-picker';
import moment from 'moment';

//import DatetimePickerComponent from '../../../common/datetime-picker/datetime-picker-config';

// imports for this component
import AddressSearchComponent from '../../../address-search/address-search';
import template from './promote-idea.html';
import './promote-idea.css';

class PromoteIdeaController {
  constructor(EventService, $stateParams, $state) {
    this.EventService = EventService;
    this.$stateParams = $stateParams;
    this.$state = $state;
    this.moment = moment;
    this.$onInit = this.$onInit.bind(this);
    this.formWarning = '';
    this.formattedStartTime = '';
    this.formattedEndTime = '';
    this.addressText = '';
    this.addressLink = '';
    this.onEndDateChange = this.onEndDateChange.bind(this);
    this.onStartDateChange = this.onStartDateChange.bind(this);
  }

  $onInit() {
    this.event = this.EventService.getEvent(this.$stateParams.eventId);
    if (!this.event.startTime) {
      this.event.startTime = this.moment().format('MM/DD/YYYY hh:mm A');
    }
    this.formattedStartTime = this.moment(this.event.startTime).format('MM/DD/YYYY hh:mm A');
    if (!this.event.endTime) {
      this.event.endTime = this.moment().format('MM/DD/YYYY hh:mm A');
    }
    this.formattedEndTime = this.moment(this.event.endTime).format('MM/DD/YYYY hh:mm A');
  }

  onStartDateChange(newValue) {
    this.formattedStartTime = newValue.format('MM/DD/YYYY hh:mm A');
  }

  onEndDateChange(newValue) {
    this.formattedEndTime = newValue.format('MM/DD/YYYY hh:mm A');
  }

  findLocation() {
    this.AddressService.findLocation();
  }

  submit() {
    if (this.validateForm()) {
      let promotedIdea = this.event;
      promotedIdea.startTime = new Date(promotedIdea.startTime);
      promotedIdea.endTime = new Date(promotedIdea.endTime);
      promotedIdea.addressText = this.addressText;
      promotedIdea.addressLink = this.addressLink;
      this.EventService.promoteEvent(promotedIdea).then(resp => {
        this.$state.go('app.plan.planner.ideas');
      }).catch(err => {
        console.log('Server error: ', err);
        this.formWarning = 'Error: please try again or contact a server admin';
      });
    }
  }

  //todo: add calendar limit for end time after start time.

  validateForm() {
    if (!this.event.title) {
      this.formWarning = 'Please enter a title';
    }
    if (!this.event.startTime) {
      this.formWarning = 'Please enter a start time';
      return false;
    }
    if (!this.event.endTime) {
      this.formWarning = 'Please enter an end time';
      return false;
    }
    return true;
  }
}
{'fraction_non_alphanumeric': 0.1470042194092827, 'fraction_numerical': 0.0, 'mean_word_length': 3.1850282485875705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3137875', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1857, 'n_words': 359}