<commit_before>_ = require('lodash')
debug = require('debug')("round-buckets:details:controller")

### @ngInject ###
module.exports = ($scope, $rootScope, $modal, $state, BucketsStore, AuthService, group, round, bucket) ->

  $rootScope.selectedBucketId = bucket.id

  setBucket = (bucket) ->
    roundBucket = _.find(
      round.buckets,
      (b) ->
        b.id == bucket.id
    )
    roundBucket.name = bucket.name
    roundBucket.description = bucket.description
    roundBucket.user = bucket.user
    roundBucket.target = bucket.target
    $scope.bucket = roundBucket

  removeBucket = (id) ->
    roundBucketIndex = _.findIndex(
      round.buckets,
      (b) -> b.id == id
    )
    round.buckets.splice(roundBucketIndex, 1)
  
  setBucket(bucket)

  isAdmin = group.isAdmin(AuthService.getCurrentUser())
  $scope.canEdit = isAdmin

  $scope.openEditBucketModal = ->
    $modal.open(
      require('bucket-modal')(
        round: round
        group: group
        bucket: $scope.bucket
        memberships: group.memberships
      )
    ).result.then (bucket) ->
      setBucket(bucket)

  $scope.openRemoveBucketModal = ->
    $modal.open(
      require('yes-or-no-modal')(
        title: "Are you sure"
        body: "you want to remove bucket #{bucket.name}?"
      )
    ).result.then ->
      debug("removing", bucket)

      BucketsStore.remove(bucket).then ->
        removeBucket(bucket.id)
        $state.go('^')
      , (err) -><commit_msg>properly remove bucket from round<commit_after>_ = require('lodash')
debug = require('debug')("round-buckets:details:controller")

### @ngInject ###
module.exports = ($scope, $rootScope, $modal, $state, BucketsStore, AuthService, group, round, bucket) ->

  $rootScope.selectedBucketId = bucket.id

  setBucket = (bucket) ->
    roundBucket = _.find(
      round.buckets,
      (b) ->
        b.id == bucket.id
    )
    roundBucket.name = bucket.name
    roundBucket.description = bucket.description
    roundBucket.user = bucket.user
    roundBucket.target = bucket.target
    $scope.bucket = roundBucket

  removeBucket = (id) ->
    roundBucketIndex = _.findIndex(
      round.buckets,
      (b) -> b.id == id
    )
    round.buckets.splice(roundBucketIndex, 1)
  
  setBucket(bucket)

  isAdmin = group.isAdmin(AuthService.getCurrentUser())
  $scope.canEdit = isAdmin

  $scope.openEditBucketModal = ->
    $modal.open(
      require('bucket-modal')(
        round: round
        group: group
        bucket: $scope.bucket
        memberships: group.memberships
      )
    ).result.then (bucket) ->
      setBucket(bucket)

  $scope.openRemoveBucketModal = ->
    $modal.open(
      require('yes-or-no-modal')(
        title: "Are you sure"
        body: "you want to remove bucket #{bucket.name}?"
      )
    ).result.then ->
      debug("removing", bucket)
      bucketId = bucket.id

      BucketsStore.remove(bucket).then ->
        removeBucket(bucketId)
        $state.go('^')
      , (err) ->
{'fraction_non_alphanumeric': 0.14059339177343222, 'fraction_numerical': 0.0006743088334457181, 'mean_word_length': 2.618292682926829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4155286', 'n_tokens_mistral': 946, 'n_tokens_neox': 922, 'n_words': 176}