<commit_before># Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

IssuesController = ($scope, $rootScope, $routeParams, $filter, $q, rs, $data, $confirm, $gmStorage) ->
    # Global Scope Variables
    $rootScope.pageSection = 'issues'
    $rootScope.pageBreadcrumb = [
        ["", ""],
        ["Issues", null]
    ]

    $rootScope.projectId = parseInt($routeParams.pid, 10)
    $scope.filtersOpened = false

    # Pagination variables
    $scope.filteredItems = []
    $scope.groupedItems = []
    $scope.itemsPerPage = 15
    $scope.pagedItems = []
    $scope.currentPage = 0

    $scope.sortingOrder = 'severity'
    $scope.reverse = true

    #####
    ## Tags generation functions
    #####

    $scope.selectedTags = []
    $scope.selectedMeta = {}

    generateTagId = (tag) ->
        return "#{tag.type}-#{tag.id or tag.name}"

    isTagSelected = (tag) ->
        return $scope.selectedMeta[generateTagId(tag)] == true

    selectTag = (tag) ->
        if $scope.selectedMeta[generateTagId(tag)] == undefined
            $scope.selectedMeta[generateTagId(tag)] = true
            $scope.selectedTags.push(tag)
        else
            delete $scope.selectedMeta[generateTagId(tag)]
            $scope.selectedTags = _.reject($scope.selectedTags,
                                        (x) -> generateTagId(tag) == generateTagId(x))


        $gmStorage.set("issues-selected-tags", $scope.selectedMeta)

        # tag.selected = if tag.selected then false else true
        $scope.currentPage = 0
        filterIssues()

        console.log $scope.selectedTags
        console.log $scope.selectedMeta

    selectTagIfNotSelected = (tag) ->
        if isTagSelected(tag)
            $scope.selectedTags.push(tag)
        return tag

    generateTagList = ->
        tagsDict = {}
        tags = []

        for iss in $scope.issues
            for tag in iss.tags
                if tagsDict[tag] is undefined
                    tagsDict[tag] = 1
                else
                    tagsDict[tag] += 1

        for key, val of tagsDict
            tag = {name:key, count:val, type: "tag"}
            tags.push(selectTagIfNotSelected(tag))

        $scope.tags = tags

    generateAssignedToTags = ->
        makeTag = (user) ->
            issues = _.filter($scope.issues, {"assigned_to": user.id})
            return {"id": user.id, "name": user.username, "count": issues.length, "type": "assigned-to"}

        $scope.assignedToTags = Lazy($scope.constants.usersList)
                                    .map(makeTag)
                                    .map(selectTagIfNotSelected).toArray()

    generateStatusTags = ->
        makeTag = (status) ->
            issues = _.filter($scope.issues, {"status": status.id})
            return {"id": status.id, "name": status.name, "count": issues.length, "type":"status"}

        $scope.statusTags = Lazy($scope.constants.issueStatusesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    generateSeverityTags = ->
        makeTag = (severity) ->
            issues = _.filter($scope.issues, {"severity": severity.id})
            return {"id": severity.id, "name": severity.name, "count": issues.length, "type": "severity"}

        $scope.severityTags = Lazy($rootScope.constants.severitiesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    generatePriorityTags = ->
        makeTag = (priority) ->
            issues = _.filter($scope.issues, {"priority": priority.id})
            return {"id": priority.id, "name": priority.name, "count": issues.length, "type": "priority"}

        $scope.priorityTags = Lazy($rootScope.constants.prioritiesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    regenerateTags = ->
        generateTagList()
        generateAssignedToTags()
        generateSeverityTags()
        generatePriorityTags()
        generateStatusTags()

    #####
    ## Filters functions
    #####

    filterIssues = ->
        for issue in $scope.issues
            issue.__hidden = false

        # Filter by generic tags
        # selectedTagsIds = _($scope.tags).filter("selected").map("name").value()
        selectedTagsIds = _($scope.tags)
                            .filter((x) -> isTagSelected(x))
                            .map("name").value()

        if selectedTagsIds.length > 0
            for item in $scope.issues
                interSection = _.intersection(selectedTagsIds, item.tags)<commit_msg>Fixed selected tag duplication on change any issue attr.<commit_after># Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

IssuesController = ($scope, $rootScope, $routeParams, $filter, $q, rs, $data, $confirm, $gmStorage) ->
    # Global Scope Variables
    $rootScope.pageSection = 'issues'
    $rootScope.pageBreadcrumb = [
        ["", ""],
        ["Issues", null]
    ]

    $rootScope.projectId = parseInt($routeParams.pid, 10)
    $scope.filtersOpened = false

    # Pagination variables
    $scope.filteredItems = []
    $scope.groupedItems = []
    $scope.itemsPerPage = 15
    $scope.pagedItems = []
    $scope.currentPage = 0

    $scope.sortingOrder = 'severity'
    $scope.reverse = true

    #####
    ## Tags generation functions
    #####

    $scope.selectedTags = []
    $scope.selectedMeta = {}

    generateTagId = (tag) ->
        return "#{tag.type}-#{tag.id or tag.name}"

    isTagSelected = (tag) ->
        return $scope.selectedMeta[generateTagId(tag)] == true

    selectTag = (tag) ->
        if $scope.selectedMeta[generateTagId(tag)] == undefined
            $scope.selectedMeta[generateTagId(tag)] = true
            $scope.selectedTags.push(tag)
        else
            delete $scope.selectedMeta[generateTagId(tag)]
            $scope.selectedTags = _.reject($scope.selectedTags,
                                        (x) -> generateTagId(tag) == generateTagId(x))


        $gmStorage.set("issues-selected-tags", $scope.selectedMeta)

        # tag.selected = if tag.selected then false else true
        $scope.currentPage = 0
        filterIssues()

    selectTagIfNotSelected = (tag) ->
        if isTagSelected(tag)
            $scope.selectedTags.push(tag)
        return tag

    generateTagList = ->
        tagsDict = {}
        tags = []

        for iss in $scope.issues
            for tag in iss.tags
                if tagsDict[tag] is undefined
                    tagsDict[tag] = 1
                else
                    tagsDict[tag] += 1

        for key, val of tagsDict
            tag = {name:key, count:val, type: "tag"}
            tags.push(selectTagIfNotSelected(tag))

        $scope.tags = tags

    generateAssignedToTags = ->
        makeTag = (user) ->
            issues = _.filter($scope.issues, {"assigned_to": user.id})
            return {"id": user.id, "name": user.username, "count": issues.length, "type": "assigned-to"}

        $scope.assignedToTags = Lazy($scope.constants.usersList)
                                    .map(makeTag)
                                    .map(selectTagIfNotSelected).toArray()

    generateStatusTags = ->
        makeTag = (status) ->
            issues = _.filter($scope.issues, {"status": status.id})
            return {"id": status.id, "name": status.name, "count": issues.length, "type":"status"}

        $scope.statusTags = Lazy($scope.constants.issueStatusesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    generateSeverityTags = ->
        makeTag = (severity) ->
            issues = _.filter($scope.issues, {"severity": severity.id})
            return {"id": severity.id, "name": severity.name, "count": issues.length, "type": "severity"}

        $scope.severityTags = Lazy($rootScope.constants.severitiesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    generatePriorityTags = ->
        makeTag = (priority) ->
            issues = _.filter($scope.issues, {"priority": priority.id})
            return {"id": priority.id, "name": priority.name, "count": issues.length, "type": "priority"}

        $scope.priorityTags = Lazy($rootScope.constants.prioritiesList)
                                .map(makeTag)
                                .map(selectTagIfNotSelected).toArray()

    regenerateTags = ->
        $scope.selectedTags = []
        generateTagList()
        generateAssignedToTags()
        generateSeverityTags()
        generatePriorityTags()
        generateStatusTags()

    #####
    ## Filters functions
    #####

    filterIssues = ->
        for issue in $scope.issues
            issue.__hidden = false

        # Filter by generic tags
        # selectedTagsIds = _($scope.tags).filter("selected").map("name").value()
        selectedTagsIds = _($scope.tags)
                            .filter((x) -> isTagSelected(x))
                            .map("name").value()

        if selectedTagsIds.length > 0
            for item in $scope.issues
                interSection = _.intersection(selectedTagsIds, item.tags)
{'fraction_non_alphanumeric': 0.1232916545507415, 'fraction_numerical': 0.0032955316467965495, 'mean_word_length': 2.05175983436853, 'pattern_counts': {'":': 40, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1670234', 'n_tokens_mistral': 2892, 'n_tokens_neox': 2758, 'n_words': 648}