<commit_before>D.Model = class Model extends D.Base

    constructor: (@app, @module, @options = {}) ->
        @data = @options.data or {}
        @params = {}

        if options.pageable
            defaults = @app.options.pagination
            p = @pagination =
                page: options.page or 1
                pageCount: 0
                pageSize: options.pageSize or defaults.defaultPageSize
                pageKey: options.pageKey or defaults.pageKey
                pageSizeKey: options.pageSizeKey or defaults.pageSizeKey
                recordCountKey: options.recordCountKey or defaults.recordCountKey

        super 'd'
        @module.container.delegateEvent @

    set: (data) ->
        @data = if D.isFunction @options.parse then @options.parse data else data
        if p = @pagination
            p.recordCount = @data[p.recordCountKey]
            p.pageCount = Math.ceil(p.recordCount / p.pageSize)
        @data = @data[@options.root] if @options.root
        @

    append: (data) ->
        if D.isObject @data
            D.extend @data, data
        else if D.isArray @data
            @data = @data.concat if D.isArray(data) then data else [data]
        @

    find: (name, value) ->
        return null unless D.isArray @data
        item for item in @data when item[name] is value

    findOne: (name, value) ->
        return null unless D.isArray @data
        return item for item in @data when item[name] is value

    url: -> @getOptionResult(@options.url) or ''

    toJSON: -> @data

    getParams: ->
        d = {}
        if p = @pagination
            d[p.pageKey] = p.page
            d[p.pageSizeKey] = p.pageSize

        D.extend d, @params, @options.params

    clear: ->
        @data = {}
        if p = @pagination
            p.page = 1
            p.pageCount = 0

    turnToPage: (page, options) ->
        return @createRejectedDeferred() unless p = @pagination and page <= p.pageCount and page >= 1
        p.page = page
        @get options

    firstPage: (options) -> @turnToPage 1, options
    lastPage: (options) -> @turnToPage @pagination.pageCount, options
    nextPage: (options) -> @turnToPage @pagination.page + 1, options
    prevPage: (options) -> @turnToPage @pagination.page - 1, options<commit_msg>fix bugs in model<commit_after>D.Model = class Model extends D.Base

    constructor: (@app, @module, @options = {}) ->
        @data = @options.data or {}
        @params = {}

        if options.pageable
            defaults = @app.options.pagination
            p = @pagination =
                page: options.page or 1
                pageCount: 0
                pageSize: options.pageSize or defaults.defaultPageSize
                pageKey: options.pageKey or defaults.pageKey
                pageSizeKey: options.pageSizeKey or defaults.pageSizeKey
                recordCountKey: options.recordCountKey or defaults.recordCountKey

        super 'd'
        @module.container.delegateEvent @

    set: (data) ->
        @data = if D.isFunction @options.parse then @options.parse data else data
        if p = @pagination
            p.recordCount = @data[p.recordCountKey]
            p.pageCount = Math.ceil(p.recordCount / p.pageSize)
        @data = @data[@options.root] if @options.root
        @

    append: (data) ->
        if D.isObject @data
            D.extend @data, data
        else if D.isArray @data
            @data = @data.concat if D.isArray(data) then data else [data]
        @

    find: (name, value) ->
        return null unless D.isArray @data
        item for item in @data when item[name] is value

    findOne: (name, value) ->
        return null unless D.isArray @data
        return item for item in @data when item[name] is value

    url: -> @getOptionResult(@options.url) or ''

    toJSON: -> @data

    getParams: ->
        d = {}
        if p = @pagination
            d[p.pageKey] = p.page
            d[p.pageSizeKey] = p.pageSize

        D.extend d, @params, @options.params

    clear: ->
        @data = {}
        if p = @pagination
            p.page = 1
            p.pageCount = 0

    turnToPage: (page, options) ->
        return @createRejectedDeferred() unless (p = @pagination) and page <= p.pageCount and page >= 1
        p.page = page
        @get options

    firstPage: (options) ->
        return @createRejectedDeferred() if (p = @pagination) and p.page is 1
        @turnToPage 1, options
    lastPage: (options) ->
        return @createRejectedDeferred() if (p = @pagination) and p.page is p.pageCount
        @turnToPage @pagination.pageCount, options
    nextPage: (options) -> @turnToPage @pagination.page + 1, options
    prevPage: (options) -> @turnToPage @pagination.page - 1, options
{'fraction_non_alphanumeric': 0.10780590717299578, 'fraction_numerical': 0.003586497890295359, 'mean_word_length': 1.9211337030191005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '772362', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1366, 'n_words': 398}