<commit_before><script lang="coffee">
import Session       from '@/shared/services/session'
import Records       from '@/shared/services/records'
import EventBus      from '@/shared/services/event_bus'
import LmoUrlService from '@/shared/services/lmo_url_service'

import { head, filter, sortBy } from 'lodash'
import { submitForm }    from '@/shared/helpers/form'

export default
  props:
    close: Function
  data: ->
    group: null
    newGroup: Records.groups.build(name: Session.user().identityFor('slack').customFields.slack_team_name)
    groupIdentity: null
    channels: []
    channel: null
  methods:
    fetchChannels: ->
      Records.identities.performCommand(Session.user().identityFor('slack').id, 'channels').then (response) =>
        @channels = response

    groups: ->
      sortBy(Session.user().adminGroups(), 'fullName')

    setSubmit: () ->
      @groupIdentity = Records.groupIdentities.build(
        groupId: @group.id
        identityType: 'slack'
        makeAnnouncement: true
      )
      @submit = submitForm @, @groupIdentity,
        prepareFn: =>
          @groupIdentity.customFields.slack_channel_id = @channel.id
          @groupIdentity.customFields.slack_channel_name = '#' + @channel.name
        flashSuccess: 'install_slack.install.slack_installed'
        successCallback: =>
          @close()
          @$router.replace({ query: {} })

  created: ->
    Records.users.fetchGroups().then =>
      @group = head(@groups())

      @fetchChannels().then =>
        @setSubmit()

</script>
<template lang="pug">
.install-slack-install-form
  loading(v-if="!group")
  v-card-text(v-if="group")
    .install-slack-install-form__add-to-group(v-if='group.id')
      p.lmo-hint-text(v-t="'install_slack.install.add_to_group_helptext'")
      v-select(return-object v-model='group' @change='setSubmit(group)' :items="groups()" item-text="fullName")

    .install-slack-install-form__add-to-group(v-if='groupIdentity')
      p.lmo-hint-text(v-t="'install_slack.invite.helptext'")
      v-select(return-object v-model='channel', :placeholder="$t('install_slack.invite.select_a_channel')" :items="channels" item-text="name")
      v-checkbox(v-model='groupIdentity.makeAnnouncement')
        div(slot="label")
          strong(v-t="'install_slack.invite.publish_group'")
          p.caption(v-t="'install_slack.invite.publish_group_helptext_on'", v-if='groupIdentity.makeAnnouncement')
          p.caption(v-t="'install_slack.invite.publish_group_helptext_off'", v-if='!groupIdentity.makeAnnouncement')

  v-card-actions.install-slack-form__actions
    v-spacer
    v-btn(color='primary' v-t="'install_slack.install.install_slack'", @click='submit()')
</template><commit_msg>slack install form<commit_after><script lang="coffee">
import Session       from '@/shared/services/session'
import Records       from '@/shared/services/records'
import EventBus      from '@/shared/services/event_bus'
import LmoUrlService from '@/shared/services/lmo_url_service'
import Flash  from '@/shared/services/flash'

import { head, filter, sortBy } from 'lodash'

export default
  props:
    close: Function
  data: ->
    group: null
    newGroup: Records.groups.build(name: Session.user().identityFor('slack').customFields.slack_team_name)
    groupIdentity: null
    channels: []
    channel: null
  methods:
    fetchChannels: ->
      Records.identities.performCommand(Session.user().identityFor('slack').id, 'channels').then (response) =>
        @channels = response

    groups: ->
      sortBy(Session.user().adminGroups(), 'fullName')

    submit: ->
      @groupIdentity.customFields.slack_channel_id = @channel.id
      @groupIdentity.customFields.slack_channel_name = '#' + @channel.name
      @groupIdentity.save().then =>
        Flash.success 'install_slack.install.slack_installed'
        @close()
        @$router.replace({ query: {} })

  created: ->
    Records.users.fetchGroups().then =>
      @group = head(@groups())

      @fetchChannels().then =>
        @groupIdentity = Records.groupIdentities.build(
          groupId: @group.id
          identityType: 'slack'
          makeAnnouncement: true
        )

</script>
<template lang="pug">
.install-slack-install-form
  loading(v-if="!group")
  v-card-text(v-if="group")
    .install-slack-install-form__add-to-group(v-if='group.id')
      p.lmo-hint-text(v-t="'install_slack.install.add_to_group_helptext'")
      v-select(return-object v-model='group' @change='setSubmit(group)' :items="groups()" item-text="fullName")

    .install-slack-install-form__add-to-group(v-if='groupIdentity')
      p.lmo-hint-text(v-t="'install_slack.invite.helptext'")
      v-select(return-object v-model='channel', :placeholder="$t('install_slack.invite.select_a_channel')" :items="channels" item-text="name")
      v-checkbox(v-model='groupIdentity.makeAnnouncement')
        div(slot="label")
          strong(v-t="'install_slack.invite.publish_group'")
          p.caption(v-t="'install_slack.invite.publish_group_helptext_on'", v-if='groupIdentity.makeAnnouncement')
          p.caption(v-t="'install_slack.invite.publish_group_helptext_off'", v-if='!groupIdentity.makeAnnouncement')

  v-card-actions.install-slack-form__actions
    v-spacer
    v-btn(color='primary' v-t="'install_slack.install.install_slack'", @click='submit()')
</template>
{'fraction_non_alphanumeric': 0.1560682798724442, 'fraction_numerical': 0.0, 'mean_word_length': 3.7227635075287866, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '972724', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1717, 'n_words': 228}