<commit_before>ViewCollection = require 'lib/view_collection'
helpers = require 'lib/helpers'
PhotoView = require 'views/photo'
Photo = require 'models/photo'
photoprocessor = require 'models/photoprocessor'
app = require 'application'

# gallery : collection of PhotoViews
module.exports = class Gallery extends ViewCollection
    itemView: PhotoView

    template: require 'templates/gallery'

    # launch photobox after render
    afterRender: ->
        super
        @$el.photobox 'a.server',
            thumbs: true
            history: false
        , @onImageDisplayed

        # Add button to return photo to left
        if $('#pbOverlay .pbCaptionText .btn-group').length is 0
            $('#pbOverlay .pbCaptionText')
                .append('<div class="btn-group"></div>')
        @turnLeft = $('#pbOverlay .pbCaptionText .btn-group .left')
        @turnLeft.unbind 'click'
        @turnLeft.remove()
        @turnLeft = $('<a id="left" class="btn left" type="button">
                       <i class="icon-share-alt"
                        style="transform: scale(-1,1)"> </i> </a>')
            .appendTo '#pbOverlay .pbCaptionText .btn-group'
        @turnLeft.on 'click', @onTurnLeft

        # Add link to download photo

        @downloadLink = $('#pbOverlay .pbCaptionText  .btn-group .download-link')
        @downloadLink.unbind 'click'
        @downloadLink.remove()
        unless @downloadLink.length
            @downloadLink =
                $('<a class="btn download-link" download>
                  <i class="icon-arrow-down"></i></a>')
                .appendTo '#pbOverlay .pbCaptionText .btn-group'

        @uploader = @$('#uploader')

        # Add button to return photo to right
        @turnRight = $('#pbOverlay .pbCaptionText .btn-group .right')
        @turnRight.unbind 'click'
        @turnRight.remove()
        @turnRight = $('<a id="right" class="btn right">
                       <i class="icon-share-alt" </i> </a>')
            .appendTo '#pbOverlay .pbCaptionText .btn-group'
        @turnRight.on 'click', @onTurnRight


    checkIfEmpty: =>
        @$('.help').toggle _.size(@views) is 0 and app.mode is 'public'

    # D&D events
    events: ->
        if @options.editable
            'drop'     : 'onFilesDropped'
            'dragover' : 'onDragOver'
            'change #uploader': 'onFilesChanged'

    # event listeners for D&D events
    onFilesDropped: (evt) ->
        @$el.removeClass 'dragover'
        @handleFiles evt.dataTransfer.files
        evt.stopPropagation()
        evt.preventDefault()
        return false

    onDragOver: (evt) ->
        @$el.addClass 'dragover'
        evt.preventDefault()
        evt.stopPropagation()
        return false

    getIdPhoto: () =>
        url = $('#pbOverlay .wrapper img.zoomable').attr 'src'
        console.log 'url: ' + url
        id = url.split('/')[4]
        id = id.split('.')[0]
        return id

    onTurnLeft: () =>
        id = @getIdPhoto()
        orientation = @collection.get(id)?.attributes.orientation
        newOrientation =
            helpers.rotateLeft orientation, $('.wrapper img.zoomable')
        helpers.rotate newOrientation, $('.wrapper img.zoomable')
        @collection.get(id)?.save orientation: newOrientation
        # Update thumb
        thumbs = $('#pbOverlay .pbThumbs img')
        for thumb in thumbs
            url = thumb.src
            idThumb = url.split('/')[5]
            idThumb = idThumb.split('.')[0]
            if idThumb is id
                thumb.style = helpers.getRotate newOrientation

    onTurnRight: () =>
        id = @getIdPhoto()
        console.log 'id: ' + id
        orientation = @collection.get(id)?.attributes.orientation
        console.log 'orientation: ' + orientation
        orientation = @collection.get(id)?.attributes.orientation
        newOrientation =
            helpers.rotateRight orientation, $('.wrapper img.zoomable')
        helpers.rotate newOrientation, $('.wrapper img.zoomable')
        console.log newOrientation<commit_msg>grab properly the id from the url<commit_after>ViewCollection = require 'lib/view_collection'
helpers = require 'lib/helpers'
PhotoView = require 'views/photo'
Photo = require 'models/photo'
photoprocessor = require 'models/photoprocessor'
app = require 'application'

# gallery : collection of PhotoViews
module.exports = class Gallery extends ViewCollection
    itemView: PhotoView

    template: require 'templates/gallery'

    # launch photobox after render
    afterRender: ->
        super
        @$el.photobox 'a.server',
            thumbs: true
            history: false
        , @onImageDisplayed

        # Add button to return photo to left
        if $('#pbOverlay .pbCaptionText .btn-group').length is 0
            $('#pbOverlay .pbCaptionText')
                .append('<div class="btn-group"></div>')
        @turnLeft = $('#pbOverlay .pbCaptionText .btn-group .left')
        @turnLeft.unbind 'click'
        @turnLeft.remove()
        @turnLeft = $('<a id="left" class="btn left" type="button">
                       <i class="icon-share-alt"
                        style="transform: scale(-1,1)"> </i> </a>')
            .appendTo '#pbOverlay .pbCaptionText .btn-group'
        @turnLeft.on 'click', @onTurnLeft

        # Add link to download photo

        @downloadLink = $('#pbOverlay .pbCaptionText  .btn-group .download-link')
        @downloadLink.unbind 'click'
        @downloadLink.remove()
        unless @downloadLink.length
            @downloadLink =
                $('<a class="btn download-link" download>
                  <i class="icon-arrow-down"></i></a>')
                .appendTo '#pbOverlay .pbCaptionText .btn-group'

        @uploader = @$('#uploader')

        # Add button to return photo to right
        @turnRight = $('#pbOverlay .pbCaptionText .btn-group .right')
        @turnRight.unbind 'click'
        @turnRight.remove()
        @turnRight = $('<a id="right" class="btn right">
                       <i class="icon-share-alt" </i> </a>')
            .appendTo '#pbOverlay .pbCaptionText .btn-group'
        @turnRight.on 'click', @onTurnRight


    checkIfEmpty: =>
        @$('.help').toggle _.size(@views) is 0 and app.mode is 'public'

    # D&D events
    events: ->
        if @options.editable
            'drop'     : 'onFilesDropped'
            'dragover' : 'onDragOver'
            'change #uploader': 'onFilesChanged'

    # event listeners for D&D events
    onFilesDropped: (evt) ->
        @$el.removeClass 'dragover'
        @handleFiles evt.dataTransfer.files
        evt.stopPropagation()
        evt.preventDefault()
        return false

    onDragOver: (evt) ->
        @$el.addClass 'dragover'
        evt.preventDefault()
        evt.stopPropagation()
        return false

    getIdPhoto: () =>
        url = $('#pbOverlay .wrapper img.zoomable').attr 'src'
        console.log 'url: ' + url
        parts = url.split('/')
        id = parts[parts.length - 1]
        id = id.split('.')[0]
        return id

    onTurnLeft: () =>
        id = @getIdPhoto()
        orientation = @collection.get(id)?.attributes.orientation
        newOrientation =
            helpers.rotateLeft orientation, $('.wrapper img.zoomable')
        helpers.rotate newOrientation, $('.wrapper img.zoomable')
        @collection.get(id)?.save orientation: newOrientation
        # Update thumb
        thumbs = $('#pbOverlay .pbThumbs img')
        for thumb in thumbs
            url = thumb.src
            idThumb = url.split('/')[5]
            idThumb = idThumb.split('.')[0]
            if idThumb is id
                thumb.style = helpers.getRotate newOrientation

    onTurnRight: () =>
        id = @getIdPhoto()
        console.log 'id: ' + id
        orientation = @collection.get(id)?.attributes.orientation
        console.log 'orientation: ' + orientation
        orientation = @collection.get(id)?.attributes.orientation
        newOrientation =
            helpers.rotateRight orientation, $('.wrapper img.zoomable')
        helpers.rotate newOrientation, $('.wrapper img.zoomable')
        console.log newOrientation
{'fraction_non_alphanumeric': 0.13026396562308165, 'fraction_numerical': 0.0019643953345610805, 'mean_word_length': 2.133076923076923, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2466502', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2296, 'n_words': 550}