View | Details | Raw Unified | Return to bug 40906
Collapse All | Expand All

(-)a/Koha/REST/V1/Mana/Reports.pm (+66 lines)
Line 0 Link Here
1
2
package Koha::REST::V1::Mana::Reports;
3
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <https://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Mojo::Base 'Mojolicious::Controller';
22
23
use Try::Tiny qw( catch try );
24
25
use Koha::SharedContent;
26
27
=head1 API
28
29
=head2 Methods
30
31
=head3 list
32
33
=cut
34
35
sub list {
36
    my $c = shift->openapi->valid_input or return;
37
38
    my $per_page = $c->param('_per_page');
39
    my $page     = $c->param('_page');
40
    my $orderby  = $c->param('_order_by');
41
42
    my $query = $c->param('q');
43
44
    my $params = {
45
        per_page => $per_page,
46
        page     => $page,
47
        orderby  => $orderby
48
    };
49
50
    if ($query) {
51
        $params->{query} = $query;
52
    }
53
54
    my $result = Koha::SharedContent::search_entities( 'report', $params );
55
    if ( $result->{pagination} ) {
56
        $c->res->headers->header( "x-total-count" => $result->{pagination}->{total} );
57
    }
58
59
    return try {
60
        return $c->render( status => 200, openapi => $result->{data} );
61
    } catch {
62
        $c->unhandled_exception($_);
63
    };
64
}
65
66
1;
(-)a/api/v1/swagger/definitions/mana_comment.yaml (+27 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    description: The id of the comment in the mana debit
6
    type: integer 
7
  resource_id:
8
    description: The id of the resource in mana the comment is linked to
9
    type: integer
10
  resource_type:
11
    description: The type of resource the comment is attached to 
12
    type: string
13
  message:
14
    description: The content of the comment
15
    type: string
16
  creationdate:
17
    description: date of creation
18
    type: string
19
    format: date
20
21
22
  
23
  
24
  
25
26
additionalProperties: false
27
(-)a/api/v1/swagger/definitions/mana_report.yaml (+63 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    type: integer
6
    description: report id in mana
7
    readOnly: true
8
  report_name:
9
    description: The name of the report
10
    type: string
11
  notes:
12
    description: A description of the report
13
    type: 
14
      - string
15
      - "null"
16
  lastimport:
17
    description: The last time the report was imported from mana
18
    format: date
19
    type:
20
      - string
21
      - "null"
22
  creationdate:
23
    description: The day the report was exported to mana
24
    type: string
25
    format: date
26
  savedsql:
27
    description: The sql of the report
28
    type:
29
      - string
30
  language:
31
    description: The language the sql report has
32
    type:
33
      - string
34
      - "null"
35
  report_group: 
36
    description: The report group the report belongs to
37
    type:
38
      - string
39
      - "null"
40
  kohaversion: 
41
    description: The version of Koha from which the report was exported to mana
42
    type: 
43
      - string
44
      - "null"
45
  nbofusers: 
46
    description: The number of import of a report 
47
    type: 
48
      - integer
49
  # Do not leave as is ! 
50
  type: 
51
    description: Type
52
    type: 
53
      - string
54
      - "null" 
55
  comments: 
56
    description: Comments added by users to the reports
57
    type: 
58
      - array
59
    items: 
60
      $ref: "../swagger.yaml#/definitions/mana_comment"
61
62
additionalProperties: false
63
(-)a/api/v1/swagger/paths/mana.yaml (+50 lines)
Line 0 Link Here
1
---
2
/mana/reports:
3
  get:
4
    x-mojo-to: Mana::Reports#list
5
    operationId: searchReports
6
    tags:
7
      - mana 
8
      - reports
9
    summary: List reports registered in the mana database 
10
    produces:
11
      - application/json
12
    parameters:
13
      - $ref: "../swagger.yaml#/parameters/match"
14
      - $ref: "../swagger.yaml#/parameters/order_by"
15
      - $ref: "../swagger.yaml#/parameters/page"
16
      - $ref: "../swagger.yaml#/parameters/per_page"
17
      - $ref: "../swagger.yaml#/parameters/q_str"
18
      - $ref: "../swagger.yaml#/parameters/request_id_header"
19
    responses:
20
      "200":
21
        description: A List of reports
22
        schema:
23
          type: array
24
          items:
25
            $ref: "../swagger.yaml#/definitions/mana_report"
26
      "400":
27
        description: |
28
          Bad request. Possible `error_code` attribute values:
29
30
            * `invalid_query`
31
        schema:
32
          $ref: "../swagger.yaml#/definitions/error"
33
      "403":
34
        description: Access forbidden
35
        schema:
36
          $ref: "../swagger.yaml#/definitions/error"
37
      "500":
38
        description: |
39
          Internal server error. Possible `error_code` attribute values:
40
41
          * `internal_server_error`
42
        schema:
43
          $ref: "../swagger.yaml#/definitions/error"
44
      "503":
45
        description: Under maintenance
46
        schema:
47
          $ref: "../swagger.yaml#/definitions/error"
48
    x-koha-authorization:
49
      permissions:
50
        catalogue: "1"
(-)a/api/v1/swagger/swagger.yaml (+12 lines)
Lines 140-145 definitions: Link Here
140
    $ref: ./definitions/library.yaml
140
    $ref: ./definitions/library.yaml
141
  list:
141
  list:
142
    $ref: ./definitions/list.yaml
142
    $ref: ./definitions/list.yaml
143
  mana_comment: 
144
    $ref: ./definitions/mana_comment.yaml
145
  mana_report:
146
    $ref: ./definitions/mana_report.yaml
143
  merge_biblios:
147
  merge_biblios:
144
    $ref: ./definitions/merge_biblios.yaml
148
    $ref: ./definitions/merge_biblios.yaml
145
  order:
149
  order:
Lines 485-490 paths: Link Here
485
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers"
489
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers"
486
  "/libraries/{library_id}/desks":
490
  "/libraries/{library_id}/desks":
487
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
491
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
492
  "/mana/reports":
493
    $ref: "./paths/mana.yaml#/~1mana~1reports"
488
  "/oauth/login/{provider_code}/{interface}":
494
  "/oauth/login/{provider_code}/{interface}":
489
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
495
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
490
  /oauth/token:
496
  /oauth/token:
Lines 967-972 parameters: Link Here
967
    items:
973
    items:
968
      type: string
974
      type: string
969
    collectionFormat: multi
975
    collectionFormat: multi
976
  q_str: 
977
    description: Query string sent as a request parameter
978
    in: query
979
    name: q
980
    required: false
981
    type: string
970
  quote_id_pp:
982
  quote_id_pp:
971
    description: Quote internal identifier
983
    description: Quote internal identifier
972
    in: path
984
    in: path
(-)a/koha-tmpl/intranet-tmpl/prog/css/reports.css (+88 lines)
Lines 21-26 del { Link Here
21
    background-color: #ffe6e6;
21
    background-color: #ffe6e6;
22
}
22
}
23
23
24
#mana_results_datatable tbody {
25
    display:flex;
26
    flex-wrap: wrap;
27
    justify-content: center;
28
}
29
30
#mana-search-result-modal-body {
31
    height: 80vh;
32
}
33
34
#overlay-report-details {
35
    display: none;
36
}
37
38
#overlay-report-details .CodeMirror {
39
    height: auto;
40
}
41
42
.return-div {
43
    font-size: 13px;
44
    cursor: pointer;
45
}
46
47
#mana_results_datatable td{
48
    width: 100%;
49
    display: inline-block;
50
    border: none;
51
    background-color: transparent;
52
    text-align: left;
53
}
54
55
#mana_results_datatable tr {
56
    display: flex;
57
    flex-wrap: wrap;
58
    justify-content: space-between;
59
    clear:both;
60
    text-align:left;
61
    width: 19rem;
62
    padding: 0.25rem;
63
    margin: 0.25rem;
64
    background-color: #E6E6E6;
65
    border: none;
66
    border-radius: 0.25rem;
67
    margin-top: 1rem;
68
    font-size: 11px;
69
    height: 14rem;
70
}
71
72
#mana_results_datatable tr:hover {
73
    cursor: pointer;
74
}
75
76
.report_name {
77
    height: 3rem;
78
    font-weight: bold;
79
}
80
81
82
83
.mana-report-comments {
84
    padding: 1rem;
85
    margin: 4px;
86
    background-color: #E6E6E6;
87
    border: none;
88
    display: flex;
89
    align-items: center;
90
    justify-content: space-between;
91
}
92
93
.report-description {
94
    height:5rem;
95
    word-wrap: break-word;
96
}
97
98
#mana_results_datatable .w-40 {
99
    width: 40%;
100
}
101
102
.report_info {
103
    color: #696969;
104
    text-align: right;
105
    margin: 0 5px;
106
}
107
108
#mana_results_datatable .text-end {
109
    text-align: right;
110
}
111
24
#col1,
112
#col1,
25
#col2 {
113
#col2 {
26
    float: left;
114
    float: left;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc (-116 lines)
Lines 1-116 Link Here
1
[% USE Asset %]
2
[% USE KohaDates %]
3
[% USE Koha %]
4
[% USE AuthorisedValues %]
5
[% USE Branches %]
6
[% USE raw %]
7
[% PROCESS 'i18n.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
<title
10
    >[% FILTER collapse %]
11
        [% t("Mana Knowledge Base reports search") | html %]
12
        &rsaquo; [% t("Reports") | html %] &rsaquo; [% t("Koha") | html %]
13
    [% END %]</title
14
>
15
[% INCLUDE 'doc-head-close.inc' %]
16
[% Asset.css("css/reports.css") | $raw %]
17
</head>
18
19
<body id="rep_mana_search" class="rep">
20
[% WRAPPER 'header.inc' %]
21
    [% INCLUDE 'circ-search.inc' %]
22
[% END %]
23
24
<div id="breadcrumbs">
25
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
26
    &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
27
    &rsaquo; Mana Knowledge Base report search results
28
</div>
29
30
[% WRAPPER 'main-container.inc' aside='guided-reports-view' %]
31
    <h2>Mana Knowledge Base report search results</h2>
32
33
    <div id="mana_results">
34
        [% IF statuscode == "200" AND reports %]
35
            <table id="mana_results_datatable">
36
                <thead>
37
                    <tr>
38
                        <th>Report name</th>
39
                        <th class="anti-the">Notes</th>
40
                        <th>Type</th>
41
                        <th title="Number of libraries using this pattern"># of users</th>
42
                        <th title="Last time a library used this pattern">Last import</th>
43
                        <th> Comments </th>
44
                        [% UNLESS search_only %]
45
                            <th class="no-sort no-export">Actions</th>
46
                        [% END %]
47
                    </tr>
48
                </thead>
49
                <tbody>
50
                    [% FOREACH report IN reports %]
51
                        [% UNLESS report.cannotdisplay %]
52
                            [% IF report.nbofcomment > highWarned %]
53
                                [% SET tr_class = 'high-warned-row' %]
54
                            [% ELSIF report.nbofcomment > warned %]
55
                                [% SET tr_class = 'warned-row' %]
56
                            [% ELSIF report.nbofcomment > lowWarned %]
57
                                [% SET tr_class = 'highlighted-row' %]
58
                            [% ELSE %]
59
                                [% SET tr_class = '' %]
60
                            [% END %]
61
                            <tr id="[% report.id | html %]" class="[% tr_class | html %]">
62
                                <td>
63
                                    <input type="hidden" class="rowid" value="[% report.id | $raw %]" />
64
                                    [% IF ( report.report_name ) %]
65
                                        [% report.report_name | html %]
66
                                    [% END %]
67
                                </td>
68
                                <td title="[% report.savedsql | html %]">
69
                                    [% IF report.notes.length > 200 %]
70
                                        <div>
71
                                            [% report.notes.substr(0,200) | html %]... <a href="#" class="btn btn-link btn-sm showbutton"><i class="fa-solid fa-square-plus"></i> Show more</a>
72
                                        </div>
73
                                        <div style="display:none">
74
                                            [% report.notes | html %]
75
                                            <a href="#" class="btn btn-link btn-sm hidebutton"><i class="fa-solid fa-square-minus"></i> Show less</a>
76
                                        </div>
77
                                    [% ELSE %]
78
                                        [% report.notes | html %]
79
                                    [% END %]
80
                                </td>
81
                                <td> [% report.type | html %] </td>
82
                                <td>
83
                                    [% IF ( report.nbofusers ) %]
84
                                        [% report.nbofusers | html %]
85
                                    [% END %]
86
                                </td>
87
                                <td data-order="[% report.lastimport | html %]"> [% report.lastimport | $KohaDates %] </td>
88
                                <td>
89
                                    [% FOREACH comment IN report.comments %]
90
                                        [% comment.message | html %]
91
                                        ([% comment.nb | html %])<br />
92
                                    [% END %]
93
                                </td>
94
95
                                [% UNLESS search_only %]
96
                                    <td>
97
                                        <button type="button" class="btn btn-default btn-xs mana-use" id="mana-use-[% report.id | html %]" data-report_id="[% report.id | html %]"><i class="fa fa-download"></i> Import</button>
98
                                    </td>
99
                                [% END %]
100
                            </tr>
101
                        [% END %]
102
                    [% END %]
103
                </tbody>
104
            </table>
105
        [% ELSE %]
106
            <h4>
107
                [% IF ( msg ) %]
108
                    [% msg | html %] <span>(Status code: [% statuscode | html %])</span>
109
                [% ELSE %]
110
                    <span>No results found</span>
111
                [% END %]
112
            </h4>
113
        [% END %]
114
    </div>
115
[% END %]
116
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (-12 / +22 lines)
Lines 185-199 Link Here
185
</div>
185
</div>
186
186
187
[% IF Koha.Preference('Mana')==1 %]
187
[% IF Koha.Preference('Mana')==1 %]
188
189
    [% INCLUDE 'js-date-format.inc' %]
188
    <div id="mana_search_result" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label">
190
    <div id="mana_search_result" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label">
189
        <div class="modal-dialog modal-lg">
191
        <div class="modal-dialog modal-xl">
190
            <form method="get" id="mana_search_form">
192
            <form method="get" id="mana_search_form">
191
                <div class="modal-content">
193
                <div class="modal-content" style="position:relative;">
192
                    <div class="modal-header">
194
                    <div class="modal-header">
193
                        <h1 class="modal-title" id="mana_search_result_label">Mana search</h1>
195
                        <h1 class="modal-title" id="mana_search_result_label">Mana search</h1>
194
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
196
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
195
                    </div>
197
                    </div>
196
                    <div class="modal-body">
198
                    <div id="mana-search-result-modal-body" class="modal-body">
199
                        <div id="overlay-report-details" class="modal-body"></div>
197
                        <div id="mana_search_failed" class="alert alert-warning mana_search_status" style="display:none">
200
                        <div id="mana_search_failed" class="alert alert-warning mana_search_status" style="display:none">
198
                            Your search could not be completed. Please try again later.
201
                            Your search could not be completed. Please try again later.
199
                            <div id="mana_search_errortext"></div>
202
                            <div id="mana_search_errortext"></div>
Lines 202-222 Link Here
202
                            This report could not be imported. Please try again later.
205
                            This report could not be imported. Please try again later.
203
                            <div id="mana_use_errortext"></div>
206
                            <div id="mana_use_errortext"></div>
204
                        </div>
207
                        </div>
205
                        <fieldset>
208
                        <div id="mana_results_datatable">
206
                            <p>
209
                            <table id="mana_result_content"></table>
207
                                Search reports by keyword:
210
                        </div>
208
                                <input type="text" id="mana_search_field" />
209
                                <input type="submit" class="mana_search_button" value="Search" />
210
                                <span id="mana-loading" style="display:none"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </span>
211
                            </p>
212
                        </fieldset>
213
                        <div id="mana_result_content"> </div>
214
                    </div>
211
                    </div>
215
                    <div class="modal-footer">
212
                    <div class="modal-footer">
216
                        <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
213
                        <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
217
                    </div>
214
                    </div>
218
                </div>
215
                </div>
219
            </form>
216
            </form>
217
            <template id="report-details-template">
218
                <td class="report_name">
219
                    <span class="font-weight-bold"></span>
220
                </td>
221
                <td class="report-description"> </td>
222
                <td class="w-40 report_info" title="Number of times this report was imported.">
223
                    <i class="fa fa-cloud-arrow-down"></i>
224
                </td>
225
                <td class="w-40 report_info text-end ms-auto" title="Creation date of the report" data-order=""> </td>
226
                <td>
227
                    <button type="button" class="btn btn-default btn-xs mana-use w-100" data-report_id=""><i class="fa fa-download"></i> Import</button>
228
                </td>
229
            </template>
220
        </div>
230
        </div>
221
    </div>
231
    </div>
222
[% END %]
232
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-details.tt (+25 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
3
<div class="return-div"><i class="fa-regular fa-arrow-left"></i> Return </div>
4
<hr />
5
<div class="p-3">
6
    <h1>[% title | html %]</h1>
7
8
    <p class="report_info" title="Number of times this report was imported."><i class="fa fa-cloud-arrow-down"></i> [% nbofusers | html %] </p>
9
    <p class="report_info" title="Creation date of the report">Created : [% creationdate | $KohaDates %]</p>
10
    <button type="button" class="btn btn-default btn-xs mana-use" id="mana-use-[% id | html %]" data-report_id="[% id | html %]"><i class="fa fa-download"></i> Import</button>
11
12
    <h3>SQL</h3>
13
    <textarea id="sql-mana" name="sql" required="required">[% savedsql | html %]</textarea>
14
15
    [% IF note %]
16
        <h3>Note</h3>
17
        <p>[% note | html %]</p>
18
    [% END %]
19
    [% IF comments %]
20
        <h3>Comments</h3>
21
        [% FOREACH comment IN comments %]
22
            <div class="mana-report-comments"> <p>[% comment.message | html %]</p><p>[% comment.creationdate | html %]</p> </div>
23
        [% END %]
24
    [% END %]
25
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt (-1 lines)
Line 1 Link Here
1
[% INCLUDE 'mana/mana-report-search-result.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-51 lines)
Lines 2175-2184 Link Here
2175
                window.history.back();
2175
                window.history.back();
2176
            });
2176
            });
2177
2177
2178
            $("body").on("click", ".mana_search_button", function(){
2179
                $("#mana-loading").show();
2180
                mana_search($("#mana_search_field").val());
2181
            });
2182
2178
2183
            $(".ShareButton").on("click", function(){
2179
            $(".ShareButton").on("click", function(){
2184
                $("#note-error").hide();
2180
                $("#note-error").hide();
Lines 2474-2488 Link Here
2474
                mana_use( $(this).data("report_id") );
2470
                mana_use( $(this).data("report_id") );
2475
            });
2471
            });
2476
2472
2477
            $("#mana_search_result").on("shown.bs.modal", function(){
2478
                $("#mana_search_field").focus();
2479
            });
2480
2481
            $("#mana_search_result").on("hide.bs.modal", function(){
2482
                $("#mana_result_content").html("");
2483
                $("#mana_search_field").val("");
2484
            });
2485
2486
            $(".batch_op").on("click", function(e){
2473
            $(".batch_op").on("click", function(e){
2487
                e.preventDefault();
2474
                e.preventDefault();
2488
                var target_form = $(this).data("submit");
2475
                var target_form = $(this).data("submit");
Lines 2598-2641 Link Here
2598
            });
2585
            });
2599
        }
2586
        }
2600
2587
2601
        function mana_search( textquery ){
2602
            $(".mana_search_status").hide();
2603
            $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", "resource=report&usecomments=1&id=" + textquery, function( response, status, xhr ) {
2604
2605
                    if ( status == "error" ) {
2606
                        $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
2607
                        $("#mana_search_failed").show();
2608
                        $("#mana-loading").hide();
2609
                    } else {
2610
                        $(".mana_search_status").hide();
2611
                        $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2612
                        $("#mana-loading").hide();
2613
                        $("#mana_results_datatable").kohaTable({
2614
                            pagingType: "full",
2615
                            autoWidth: false,
2616
                            columnDefs: [
2617
                                { "width": "35%", targets: 1 }
2618
                            ],
2619
                        });
2620
2621
                        $(".showbutton").on("click", function(e){
2622
                            e.preventDefault();
2623
                            $(this).parent().hide();
2624
                            $(this).parent().next().show();
2625
                        });
2626
2627
                        $(".hidebutton").on("click", function(e){
2628
                            e.preventDefault();
2629
                            $(this).parent().hide();
2630
                            $(this).parent().prev().show();
2631
                        });
2632
2633
                        if($("td.dataTables_empty").length == 0){
2634
                            $("#mana_search_message").show();
2635
                        }
2636
                    }
2637
                });
2638
        }
2639
2588
2640
        function addToList() {
2589
        function addToList() {
2641
            var biblionumbers = [];
2590
            var biblionumbers = [];
(-)a/koha-tmpl/intranet-tmpl/prog/js/mana.js (+132 lines)
Lines 93-96 $(document).ready(function () { Link Here
93
            mana_increment(commentid, "resource_comment", "nb");
93
            mana_increment(commentid, "resource_comment", "nb");
94
        }
94
        }
95
    });
95
    });
96
97
    //Open mana report details
98
    $("body").on("click", "#mana_results_datatable tr", function (e) {
99
        let targeted_element = e.currentTarget;
100
101
        if (targeted_element.classList.contains("mana-use")) {
102
            return;
103
        }
104
105
        const id_ = targeted_element.id;
106
        let overlay_detail = $("#overlay-report-details")[0];
107
        overlay_detail.style.display = "block";
108
109
        let table = $("#mana_results_datatable")[0];
110
        table.style.display = "none";
111
112
        $.ajax({
113
            url: "/cgi-bin/koha/reports/mana_report_details.pl",
114
115
            data: {
116
                id: id_,
117
            },
118
            dataType: "html",
119
        }).done(function (data) {
120
            overlay_detail.innerHTML = data;
121
            let modal_body = $(".modal-body");
122
            let sql = $("#sql-mana")[0];
123
124
            modal_body.scrollTop(0);
125
126
            showsql = CodeMirror.fromTextArea(sql, {
127
                lineNumbers: false,
128
                mode: "text/x-sql",
129
                lineWrapping: true,
130
                readOnly: true,
131
            });
132
        });
133
134
        $("body").on("click", ".return-div", function (e) {
135
            let overlay_detail = $("#overlay-report-details")[0];
136
            overlay_detail.style.display = "none";
137
            overlay_detail.innerHTML = "";
138
139
            let table = $("#mana_results_datatable")[0];
140
            table.style.display = "block";
141
        });
142
143
        $("#mana_search_result")[0].addEventListener(
144
            "hidden.bs.modal",
145
            event => {
146
                let overlay_detail = $("#overlay-report-details")[0];
147
                overlay_detail.style.display = "none";
148
                overlay_detail.innerHTML = "";
149
150
                let table = $("#mana_results_datatable")[0];
151
                table.style.display = "block";
152
            }
153
        );
154
    });
155
156
    //Creates datatable
157
    $("#mana_search_result")[0].addEventListener("show.bs.modal", event => {
158
        if ($.fn.dataTable.isDataTable("#mana_result_content")) {
159
            return;
160
        }
161
162
        let table = $("#mana_result_content").kohaTable({
163
            autoWidth: false,
164
            fixedHeader: false,
165
            serverSide: true,
166
            ajax: {
167
                url: "/api/v1/mana/reports",
168
                data: function (data, setting) {
169
                    var length = data.length;
170
                    var start = data.start;
171
                    var dataSet = {
172
                        _page: Math.floor(start / length) + 1,
173
                        _per_page: length,
174
                        _order_by: "",
175
                    };
176
177
                    //This is why the kohaTables data function is overwritten, to allow passing the search query as a string.
178
                    if (data.search) {
179
                        dataSet.q = data.search.value;
180
                    }
181
                    return dataSet;
182
                },
183
            },
184
            createdRow: function (row, data, dataIndex) {
185
                let template = $("#report-details-template")[0];
186
                const clone = document.importNode(template.content, true);
187
                //changer id de la row
188
                const title = clone.querySelector("span");
189
                const description = clone.querySelectorAll("td")[1];
190
                const nbofuser_place = clone.querySelector(".report_info");
191
                const creationdate_place =
192
                    clone.querySelectorAll(".report_info")[1];
193
                const button = clone.querySelector("button");
194
195
                title.textContent = data.report_name;
196
                if (data.notes.length > 100) {
197
                    data.notes = data.notes.slice(0, 100) + "...";
198
                }
199
                description.textContent = data.notes;
200
201
                nbofuser_place.append(data.nbofusers);
202
                creationdate_place.textContent = $date(data.creationdate);
203
                button.id = "mana-use-".concat(data.id);
204
                button.setAttribute("data-report_id", data.id);
205
206
                row.id = data.id;
207
                row.innerHTML = "";
208
                row.appendChild(clone);
209
            },
210
211
            columns: [
212
                { data: "id" },
213
                { data: "report_name" },
214
                { data: "notes" },
215
                { data: "nbofusers" },
216
                { data: "lastimport" },
217
            ],
218
        });
219
220
        let thead = $("#mana_results_datatable thead");
221
        thead.addClass("visually-hidden");
222
223
        table.on("draw", function () {
224
            let thead = $("#mana_results_datatable thead")[0];
225
            thead.addClass("visually-hidden");
226
        });
227
    });
96
});
228
});
(-)a/reports/mana_report_details.pl (+43 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Koha::SharedContent;
6
use C4::Auth qw(check_cookie_auth);
7
use Koha::Report;
8
9
use C4::Auth   qw(get_template_and_user);
10
use C4::Output qw( output_html_with_http_headers );
11
12
use CGI;
13
use JSON;
14
15
my $input = CGI->new;
16
17
my $templatename = 'mana/mana-report-details.tt';
18
19
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
20
    {
21
        template_name => $templatename,
22
        query         => $input,
23
        type          => 'intranet'
24
    }
25
);
26
27
my $result = Koha::SharedContent::get_entity_by_id(
28
    "report",
29
    scalar $input->param('id'),
30
    { usecomments => 1 }
31
);
32
33
$template->param(
34
    id           => $result->{data}->{id},
35
    title        => $result->{data}->{report_name},
36
    savedsql     => $result->{data}->{savedsql},
37
    note         => $result->{data}->{notes},
38
    nbofusers    => $result->{data}->{nbofusers},
39
    creationdate => $result->{data}->{creationdate},
40
    comments     => $result->{data}->{comments}
41
);
42
43
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/svc/mana/search (-6 / +1 lines)
Lines 30-40 use CGI; Link Here
30
my $input = CGI->new;
30
my $input = CGI->new;
31
31
32
my $templatename;
32
my $templatename;
33
if ( $input->param("resource") eq 'report' ) {
33
$templatename = "mana/mana-subscription-search-result.tt";
34
    $templatename = "mana/mana-report-search-result.tt";
35
} else {
36
    $templatename = "mana/mana-subscription-search-result.tt";
37
}
38
34
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {
36
    {
41
- 

Return to bug 40906