<commit_before>##= require_self
##= require ./EditWrapper
##= require ./PopoverEdit
##= require ./WeekSummary
##= require ./Entries

class Skr.Screens.TimeTracking extends Skr.Screens.Base

    dataObjects:
        entries: ->
            new Skr.Screens.TimeTracking.Entries

    back: ->
        @entries.back()

    forward: ->
        @entries.forward()

    onAddEntry: (ev, date) ->
        rounded = Math.round( date.minute() / 15 ) * 15
        date.minute(rounded).second(0)
        entry = @entries.add(
            start_at: date, end_at: date.clone().add(2, 'hour')
        )
        event = @entries.calEvents().add( _.extend(entry.toCalEvent(), {
            onTop: (0.5 < ev.clientY / this.context.viewport.domRoot.clientHeight)
            onLeft: (0.5 < ev.clientX / this.context.viewport.domRoot.clientWidth)
        }))
        @entries.startEditing(event)

    onEventClick: (ev, event) ->
        if event.isEditing() then event.set(editing: false) else @entries.startEditing(event)

    editComponent: (props) ->
        <Skr.Screens.TimeTracking.EditWrapper {...props} parent={this} />

    startEdit: (wrapper, edit) ->
        @setState({edit: {
            wrapper, entries: @entries, container: @, event: edit.event,
            entry: edit.event.get('entry')
        }})

    stopEdit: ->
        @setState(edit: false)

    onEventResize: (ev, event) ->
        entry = event.get('entry')
        entry.fromCalEvent(event)
        entry.save() unless entry.isNew()

    changeDisplay: (ev) ->
        @entries.display = ev.target.value

    ProjectOption: (props) ->
        color = props.item.options?.color || 0
        <div className={"color-#{color}"}>{props.item.code}</div>

    setProject: (project) ->
        @entries.set(customer_project_id: project.id)

    getProjects: ->
        @entries.available_projects.models

    renderSummaryDays: ->
        return null unless @entries.isMonth
        for week in [1..5]
            <Skr.Screens.TimeTracking.WeekSummary
                key={week} week={week} entries={@entries} />

    renderTotals: ->
        return null unless @entries.isMonth
        <div className="monthly-totals">{@entries.totalHours().toFixed(2)}</div>

    render: ->
        <LC.ScreenWrapper identifier="time-tracking">
            <BS.Row className='calendar-header'>

                <div className="paging">

                    <span className="legend">
                        {@entries.calLegend}
                    </span>

                    <BS.ButtonGroup>
                        <BS.Button bsSize="small" onClick={@back}><commit_msg>Display network activity<commit_after>##= require_self
##= require ./EditWrapper
##= require ./PopoverEdit
##= require ./WeekSummary
##= require ./Entries

class Skr.Screens.TimeTracking extends Skr.Screens.Base

    dataObjects:
        entries: ->
            new Skr.Screens.TimeTracking.Entries

    back: ->
        @entries.back()

    forward: ->
        @entries.forward()

    onAddEntry: (ev, date) ->
        rounded = Math.round( date.minute() / 15 ) * 15
        date.minute(rounded).second(0)
        entry = @entries.add(
            start_at: date, end_at: date.clone().add(2, 'hour')
        )
        event = @entries.calEvents().add( _.extend(entry.toCalEvent(), {
            onTop: (0.5 < ev.clientY / this.context.viewport.domRoot.clientHeight)
            onLeft: (0.5 < ev.clientX / this.context.viewport.domRoot.clientWidth)
        }))
        @entries.startEditing(event)

    onEventClick: (ev, event) ->
        if event.isEditing() then event.set(editing: false) else @entries.startEditing(event)

    editComponent: (props) ->
        <Skr.Screens.TimeTracking.EditWrapper {...props} parent={this} />

    startEdit: (wrapper, edit) ->
        @setState({edit: {
            wrapper, entries: @entries, container: @, event: edit.event,
            entry: edit.event.get('entry')
        }})

    stopEdit: ->
        @setState(edit: false)

    onEventResize: (ev, event) ->
        entry = event.get('entry')
        entry.fromCalEvent(event)
        entry.save() unless entry.isNew()

    changeDisplay: (ev) ->
        @entries.display = ev.target.value

    ProjectOption: (props) ->
        color = props.item.options?.color || 0
        <div className={"color-#{color}"}>{props.item.code}</div>

    setProject: (project) ->
        @entries.set(customer_project_id: project.id)

    getProjects: ->
        @entries.available_projects.models

    renderSummaryDays: ->
        return null unless @entries.isMonth
        for week in [1..5]
            <Skr.Screens.TimeTracking.WeekSummary
                key={week} week={week} entries={@entries} />

    renderTotals: ->
        return null unless @entries.isMonth
        <div className="monthly-totals">{@entries.totalHours().toFixed(2)}</div>

    render: ->
        <LC.ScreenWrapper identifier="time-tracking">
            <LC.NetworkActivityOverlay visible={@entries.isLoading} model={@entries}/>
            <BS.Row className='calendar-header'>

                <div className="paging">

                    <span className="legend">
                        {@entries.calLegend}
                    </span>

                    <BS.ButtonGroup>
                        <BS.Button bsSize="small" onClick={@back}>
{'fraction_non_alphanumeric': 0.14497931553215496, 'fraction_numerical': 0.0052651372696502444, 'mean_word_length': 2.1380530973451326, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 62, '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': '4817381', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1553, 'n_words': 286}