check_validate.html 11.1 KB
Newer Older
1
{{
2 3 4 5 6 7 8 9

    #--------------------------------------------------------------------------
    # The python controller return:
    #    - logs (List of Storage)
    #    - selector (Selector)
    #    - counters (dict of Storage) the key are the project
    #      The storage keys are: found, ok, validated
    #
10 11 12
    #--------------------------------------------------------------------------
    #
    # prepare the data
13
    #    - create URL for id, ids and title
14 15
    #    - configure the Ext.data.Array for the statistics
    #    - configure the Ext.data.Array for the logs
16 17 18 19 20
    #    - configure the field name for the Ext.form.Panel
    #    - the title of the HTML page
    #    - the DIV blocks
    #    - the HTML page footer
    #    - export python variables to the javascript
21 22
    #
    #--------------------------------------------------------------------------
23
    import json
24
    from datetime import datetime
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    #
    # create the URL to compare id and ids
    # modified the content of the row.title
    #
    for row in logs:
        for i in range(len(row.ids)):
            url = URL('wizards',
                      'compare_publications',
                       vars=dict(id1=row.id, id2=row.ids[i]))

            row.ids[i] = str(A(row.ids[i], _href=url, _target="_blank"))
        pass
    pass

    #
    # create the URL pointing to the record in the havest store
    # modified the content of the row.ids
    #
    for row in logs:
        origin = db.publications[row.id].origin
        if origin:
47 48
            origin = origin.split(",")
            origin = origin[0].strip()
49 50 51 52 53 54 55 56 57
            row.title = str(A(row.title, _href=origin, _target="_blank"))
        pass
    pass

    #
    # create the URL to edit the id
    # modified the content of the row.id
    #
    for row in logs:
58
        script = "javascript:Limbra.onGridLogClick(%i)" % row.id
59 60 61
        row.id = str(A(row.id, _href=script))
    pass

62
    #.........................................................................
63
    #
64
    # configure the Ext.data.Array for the statistics
65
    #
66
    cfg = dict(sorters=['project'], data=[])
67

68
    cfg['fields'] = [{'name': 'records', 'type': 'int'},
69 70 71 72 73 74 75 76
                     {'name': 'ok', 'type': 'int'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'validated', 'type': 'int'},
                     {'name': 'error', 'type': 'int'}]

    for project in counters:
        counter = counters[project]
        error = counter.found - counter.ok - counter.validated
77 78 79 80 81 82
        record = [counter.found,
                  counter.ok,
                  project,
                  counter.validated,
                  error]
        cfg['data'].append(record)
83 84 85
    pass

    cfg_statStore =  json.dumps(cfg)
86

87
    #.........................................................................
88
    #
89
    # configure the Ext.data.Array for the logs
90
    #
91 92
    cfg = dict(data=[],
               groupField='txt',
93 94 95
               sorters=['txt', 'title'])

    cfg['fields'] = [{'name': 'category', 'type': 'string'},
96
                     {'name': 'id', 'type': 'string'},
97 98 99 100 101 102 103
                     {'name': 'ids', 'type': 'string'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'title', 'type': 'string'},
                     {'name': 'txt', 'type': 'string'},
                     {'name': 'year', 'type': 'int'}]

    for row in logs:
104
        for txt in row.txt:
105 106 107 108 109 110 111 112
            record = [row.category,
                      row.id,
                      ','.join(row.ids),
                      row.project,
                      row.title,
                      txt,
                      row.year]
            cfg['data'].append(record)
113
        pass
114
    pass
115

116
    cfg_logsStore =  json.dumps(cfg)
117

118
    #.........................................................................
119
    #
120
    # configure the field name for the Ext.form.Panel
121
    #
122
    # HACK:
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    # simplify the encoding of the field name for the form (TableField → field)
    # NOTE: for publication fields are organized in tabPanel
    # FIXME: awfull piece of code. Have to solve it in plugin_dbbui
    #
    items = json.loads(publications_fields)

    for tabPanel in items:
        for tab in tabPanel['items']:
            for field in tab['items']['items']:
                if field['xtype'] == 'fieldcontainer':
                    for el in field['items']:
                        el['name'] = el['name'].replace("Publications", "").lower()
                    pass
                else:
                    field['name'] = field['name'].replace("Publications", "").lower()
                pass
            pass
        pass
    pass

    publications_fields = json.dumps(items)

145
    #.........................................................................
146
    #
147
    # the title of the HTML page
148 149 150 151
    #
    period = ""
    if selector.year:
        period = selector.year
152
    pass
153

154 155 156 157
    team = ""
    if selector.id_teams:
        team = db.teams[selector.id_teams].team
    pass
158

159 160 161 162
    project = ""
    if selector.id_projects:
        project = db.projects[selector.id_projects].project
    pass
163

164 165 166 167
    if team and not project:
        project = team
    elif team and project:
        project = "%s / %s" % (team, project)
168
    pass
169

170 171 172 173 174 175 176 177 178 179
    title = "%s %s %s" % (T("Check and validate"), project, period)

    style = ["font-size: 12px;",
             "font-variant: small-caps;",
             "margin-left: 10px;",
             "margin-bottom: 3ex;",
             "margin-top: 2ex;"]

    response.write(P(title, _style="".join(style)))

180
    #.........................................................................
181 182 183
    #
    # the DIV block, one for each grid
    #
184 185
    divlogs = "grid-%s" % id(cfg_logsStore)
    divstat = "grid-%s" % id(cfg_statStore)
186

187 188
    response.write(DIV(_id=divstat))
    response.write(DIV(_id=divlogs))
189

190
    #.........................................................................
191 192 193 194 195
    #
    # the HTML page footer:  processing time of the request
    #
    delta = (datetime.now()-request.now).total_seconds()
    delta = T('Check and validate took %s seconds') % round(delta, 2)
196

197 198 199 200
    style = ["font-size: 10px;",
             "margin-left: 10px;",
             "margin-bottom: 3ex;",
             "margin-top: 2ex;"]
201

202
    response.write(P(delta, _style="".join(style)))
203

204 205
}}
<script type="text/javascript">
206

207 208 209 210 211 212
    /**
     * handler to instantiate the form allowing to modify a publication record.
     *
     * @param {Number} publicationId
     *
     */
213
    Limbra.onGridLogClick = function (publicationId) {
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

        var actionLoad,
            actionSubmit,
            formPanel,
            window;

        //
        // define actions
        //
        actionLoad = {
            url: urlRead,
            params: {
                id: publicationId
            }
        };

        actionSubmit = {
            success: function () {
                window.close();
            },
            failure: function (form, action) {
                Ext.Msg.alert('Update failed', action.result.msg);
            }
        };

        //
        // instantiate the form
        // load it with the selected record
        //
        formPanel =  Ext.create('Ext.form.Panel', {
            buttons: [{
                formBind: true,
                text: trUpdate,
                handler: function () {
                    var btn = this;
                    btn.up('form').submit(actionSubmit);
                }
            }],
            items: fields,
            url: urlUpdate,
254
            width: 450
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
        });

        formPanel.load(actionLoad);

        //
        // instantiate the window and show it
        //
        window = Ext.create('Ext.window.Window', {
            closeAction: 'destroy',
            items: formPanel,
            layout: 'fit',
            modal: true,
            plain: true,
            title: trRecord.concat(" ",publicationId.toString())
        });

        window.show();
    }

274
    /**
275 276 277 278 279 280 281 282 283 284
     * Renderer functions
     *
     * @param {Object} value
     * @param {Object} metadata
     * @param {Ext.data.Model} record
     * @param {Number} rowIndex
     * @param {Number} colIndex
     * @param {Ext.data.Store} store
     * @param {Ext.view.view} view
     *
285 286 287 288 289
     */
    function rTotal() {
        return 'Total';
    }

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    var cfgLogsStore = {{=XML(cfg_logsStore)}},
        cfgStatStore = {{=XML(cfg_statStore)}},
        fields = {{=XML(publications_fields)}},
        trCategory = '{{=T("Category")}}',
        trCollection = '{{=T("Collection")}}',
        trDuplicate = '{{=T("Duplicate")}}',
        trError = '{{=T("Error")}}',
        trId = '{{=T("Id")}}',
        trInvalid = '{{=T("Invalid")}}',
        trProject = '{{=T("Project")}}',
        trRecord = '{{=T("Record")}}',
        trRecords = '{{=T("Records")}}',
        trStatistics = '{{=T("Statistics")}}',
        trStatusOK = '{{=T("Status OK")}}',
        trTitle = '{{=T("Title")}}',
        trUpdate = '{{=T("Update")}}',
        trValidated = '{{=T("Validated")}}',
        trYear = '{{=T("Year")}}',
        urlRead = '{{=URL("publications", "read")}}',
        urlUpdate = '{{=URL("publications", "update")}}',
        gridLog, gridStat;

312
    //
313
    // instantiate the grid showing the statistics
314
    //
315
    gridStat = Ext.create('Ext.grid.Panel', {
316 317 318
        title: trStatistics,
        store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
        columns: [
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
            {
                xtype: 'rownumberer'
            }, {
                text: trProject,
                dataIndex: 'project',
                flex: 2,
                summaryRenderer: rTotal
            }, {
                text: trRecords,
                dataIndex: 'records',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trStatusOK,
                dataIndex: 'ok',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trValidated,
                dataIndex: 'validated',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trInvalid,
                dataIndex: 'error',
                flex: 1,
                summaryType: 'sum'
            }
347
        ],
LE GAC Renaud's avatar
LE GAC Renaud committed
348
        collapsible: true,
349 350 351
        forceFit: true,
        features: [{ftype:'summary'}],
        padding: "0 40 20 30",
352
        renderTo: '{{=divstat}}'
353 354
    });

355
    //
356
    // instantiate the grid showing the log for each publication.
357
    //
358
    gridLog = Ext.create('Ext.grid.Panel', {
359 360 361 362
        store: Ext.create('Ext.data.ArrayStore', cfgLogsStore),
        columns: [
            {xtype: 'rownumberer'},
            {text: trTitle, dataIndex: 'title', flex: 3},
363
            {text: trError, dataIndex: 'txt', hidden: true},
364
            {text: trId, dataIndex: 'id', flex: 0.2},
365 366 367 368
            {text: trDuplicate, dataIndex: 'ids', flex: 0.4},
            {text: trCategory, dataIndex: 'category', flex: 0.2},
            {text: trProject, dataIndex: 'project', flex: 0.5},
            {text: trYear, dataIndex: 'year', flex: 0.2}
369 370 371 372 373 374
        ],
        features: [
            {ftype:'grouping', groupHeaderTpl: '{name}', startCollapsed: true}
        ],
        forceFit: true,
        padding: "10 40 20 30",
375
        renderTo: '{{=divlogs}}'
376 377
    });

378
</script>