From b0dfc6bca65c57a3cb8fda7993fa1391fdabe13b Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 11:46:35 +0100 Subject: [PATCH 01/18] draft articleinfo --- portality/forms/application_forms.py | 6 ++++-- portality/static/js/formulaic.js | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index b370d29051..490269ad52 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -1881,7 +1881,8 @@ class FieldDefinitions: "entry_template": "application_form/_entry_group.html", "widgets": [ {"infinite_repeat" : {"enable_on_repeat" : ["textarea"]}}, - "note_modal" + "note_modal", + "article_info", ], "merge_disabled" : "merge_disabled_notes", } @@ -3042,7 +3043,8 @@ def wtforms(field, settings): "trim_whitespace" : "formulaic.widgets.newTrimWhitespace", # ~~-> TrimWhitespace:FormWidget~~ "note_modal" : "formulaic.widgets.newNoteModal", # ~~-> NoteModal:FormWidget~~ "autocheck": "formulaic.widgets.newAutocheck", # ~~-> Autocheck:FormWidget~~ - "issn_link" : "formulaic.widgets.newIssnLink" # ~~-> IssnLink:FormWidget~~, + "issn_link" : "formulaic.widgets.newIssnLink", # ~~-> IssnLink:FormWidget~~, + "article_info": "formulaic.widgets.newArticleInfo", # ~~-> ArticleInfo:FormWidget~~ } diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 0c5932c3ce..7ae33d0a9a 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -1155,14 +1155,14 @@ var formulaic = { this._renderAutocheck = function(autocheck) { let frag = "
  • "; - + if (autocheck.checked_by && doaj.autocheckers && doaj.autocheckers.registry.hasOwnProperty(autocheck.checked_by)) { frag += (new doaj.autocheckers.registry[autocheck.checked_by]()).draw(autocheck) } else { frag += this._defaultRender(autocheck); } - + frag += `
  • `; return frag; } @@ -2252,5 +2252,20 @@ var formulaic = { this.init(); }, + + newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), + ArticleInfo: function ({formulaic, fieldDef, args}) { + const init = () => { + console.log() + console.log(this.fieldDef); + debugger + }; + + init(); + }, + + + + } }; From edcd98adb884e40eab5f4c86eeddea9054e9f402 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 13:03:14 +0100 Subject: [PATCH 02/18] implement ArticleInfo --- portality/static/js/formulaic.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 7ae33d0a9a..ec438f321d 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2256,9 +2256,15 @@ var formulaic = { newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), ArticleInfo: function ({formulaic, fieldDef, args}) { const init = () => { - console.log() - console.log(this.fieldDef); - debugger + const paths = window.location.pathname.split('/') + const journalId = paths[paths.length - 1] + fetch(`/admin/journal/${journalId}/article-info`) + .then(response => response.json()) + .then(data => { + const $p = $('.doaj_seal__container').prev('p'); + const text = $p.text() + $p.text(text + `This journal has ${data.n_articles} articles in DOAJ.`) + }) }; init(); From c90cda05b647c8d1a042482aeee35b5570c9232c Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 13:06:24 +0100 Subject: [PATCH 03/18] update dictionary --- docs/dictionary.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/dictionary.md b/docs/dictionary.md index 49ba798b8f..fcbee273d9 100644 --- a/docs/dictionary.md +++ b/docs/dictionary.md @@ -1,10 +1,11 @@ -| Short | Description | -|---------|------------------------------| -| bgjob | background job | -| noti | notification | -| noqa | NO-QA (NO Quality Assurance) | -| inst | instance | -| fmt | format | -| exparam | extra parameter | -| maned | Managing Editor | -| gsheet | Google Sheet | \ No newline at end of file +| Short | Description | +|----------|------------------------------| +| bgjob | background job | +| noti | notification | +| noqa | NO-QA (NO Quality Assurance) | +| inst | instance | +| fmt | format | +| exparam | extra parameter | +| maned | Managing Editor | +| gsheet | Google Sheet | +| svc,serv | service | \ No newline at end of file From dcd962af3b2c966f2a91d69e5495f80d9b03f47b Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 13:06:53 +0100 Subject: [PATCH 04/18] setup article_info widgets --- portality/forms/application_forms.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index 490269ad52..71dde93891 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -1603,7 +1603,7 @@ class FieldDefinitions: # ~~->$ DOAJSeal:FormField~~ DOAJ_SEAL = { "name": "doaj_seal", - "label": "The journal has fulfilled all the criteria for the Seal. Award the Seal?", + "label": "Award the Seal?", "input": "checkbox", "validate": [ { @@ -1626,7 +1626,10 @@ class FieldDefinitions: "the journal must use a persistent identifier" } } - ] + ], + "widgets": [ + "article_info", + ], } # FIXME: this probably shouldn't be in the admin form fieldsets, rather its own separate form @@ -1882,7 +1885,6 @@ class FieldDefinitions: "widgets": [ {"infinite_repeat" : {"enable_on_repeat" : ["textarea"]}}, "note_modal", - "article_info", ], "merge_disabled" : "merge_disabled_notes", } From 969c687d7d3eff26fcb6b2174f0358ea11a41c32 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 13:44:21 +0100 Subject: [PATCH 05/18] implement query of journal_article_info --- portality/view/admin.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/portality/view/admin.py b/portality/view/admin.py index 484441a02a..187aee04ee 100644 --- a/portality/view/admin.py +++ b/portality/view/admin.py @@ -7,13 +7,14 @@ from flask_login import current_user, login_required from werkzeug.datastructures import MultiDict -from portality import dao import portality.models as models from portality import constants +from portality import dao from portality import lock from portality.background import BackgroundSummary from portality.bll import DOAJ, exceptions from portality.bll.exceptions import ArticleMergeConflict, DuplicateArticleException +from portality.bll.services.query import Query from portality.core import app from portality.crosswalks.application_form import ApplicationFormXWalk from portality.decorators import ssl_required, restrict_to_role, write_required @@ -28,8 +29,6 @@ from portality.ui.messages import Messages from portality.util import flash_with_url, jsonp, make_json_resp, get_web_json_payload, validate_json from portality.view.forms import EditorGroupForm, MakeContinuation - -from portality.bll.services.query import Query from portality.view.view_helper import exparam_editing_user # ~~Admin:Blueprint~~ @@ -322,6 +321,15 @@ def journals_bulk_reinstate(): # ##################################################################### +@blueprint.route("/journal//article-info/", methods=["GET"]) +def journal_article_info(journal_id): + j = models.Journal.pull(journal_id) + if j is None: + abort(404) + + return {'n_articles': models.Article.count_by_issns(j.bibjson().issns())} + + @blueprint.route("/journal//continue", methods=["GET", "POST"]) @login_required @ssl_required @@ -432,7 +440,8 @@ def application(application_id): flash(str(e)) return redirect(url_for("admin.application", application_id=ap.id, _anchor='cannot_edit')) else: - return fc.render_template(obj=ap, lock=lockinfo, form_diff=form_diff, current_journal=current_journal, lcc_tree=lcc_jstree, autochecks=autochecks) + return fc.render_template(obj=ap, lock=lockinfo, form_diff=form_diff, current_journal=current_journal, + lcc_tree=lcc_jstree, autochecks=autochecks) @blueprint.route("/application_quick_reject/", methods=["POST"]) From 3dcc38ddc02e60684958383ed990a5ec4cff0803 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 13:49:12 +0100 Subject: [PATCH 06/18] add checking before init --- portality/static/js/formulaic.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index ec438f321d..07d986f987 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2255,19 +2255,26 @@ var formulaic = { newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), ArticleInfo: function ({formulaic, fieldDef, args}) { + const sealSelector = '.doaj_seal__container' + const init = () => { const paths = window.location.pathname.split('/') const journalId = paths[paths.length - 1] fetch(`/admin/journal/${journalId}/article-info`) .then(response => response.json()) .then(data => { - const $p = $('.doaj_seal__container').prev('p'); + const $p = $(sealSelector).prev('p'); const text = $p.text() $p.text(text + `This journal has ${data.n_articles} articles in DOAJ.`) }) }; - init(); + + if ($(sealSelector).length) { + init(); + } else { + console.log('skip ArticleInfo, seal section not found') + } }, From 96ac2eb3f8aa8fb26f05f6297b8d7f703590e0a2 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 15 Apr 2024 16:33:55 +0100 Subject: [PATCH 07/18] add test cases --- doajtest/fixtures/accounts.py | 6 ++- doajtest/helpers.py | 4 +- .../api_tests/test_api_crud_returnvalues.py | 5 +-- doajtest/unit/test_view_admin.py | 37 +++++++++++++++++++ portality/view/admin.py | 1 + 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 doajtest/unit/test_view_admin.py diff --git a/doajtest/fixtures/accounts.py b/doajtest/fixtures/accounts.py index a36dd60c6f..4b974490fc 100644 --- a/doajtest/fixtures/accounts.py +++ b/doajtest/fixtures/accounts.py @@ -83,7 +83,11 @@ def create_publisher_a(): return publisher -def create_maned_a(): +def create_maned_a(is_save=False): from portality import models maned = models.Account(**AccountFixtureFactory.make_managing_editor_source()) + maned.set_password("password") + if is_save: + maned.save(blocking=True) return maned + diff --git a/doajtest/helpers.py b/doajtest/helpers.py index a8f33d52d5..0cd4fb76fb 100644 --- a/doajtest/helpers.py +++ b/doajtest/helpers.py @@ -410,9 +410,9 @@ def assert_expected_dict(test_case: TestCase, target, expected: dict): test_case.assertDictEqual(actual, expected) -def login(app_client, username, password, follow_redirects=True): +def login(app_client, email, password, follow_redirects=True): return app_client.post(url_for('account.login'), - data=dict(user=username, password=password), + data=dict(user=email, password=password), follow_redirects=follow_redirects) diff --git a/doajtest/unit/api_tests/test_api_crud_returnvalues.py b/doajtest/unit/api_tests/test_api_crud_returnvalues.py index 1d708b4224..b398d0d236 100644 --- a/doajtest/unit/api_tests/test_api_crud_returnvalues.py +++ b/doajtest/unit/api_tests/test_api_crud_returnvalues.py @@ -1,3 +1,4 @@ +from doajtest import helpers from doajtest.helpers import DoajTestCase, with_es from portality import models from doajtest.fixtures import ApplicationFixtureFactory, ArticleFixtureFactory, JournalFixtureFactory @@ -205,9 +206,7 @@ def test_04_article_structure_exceptions(self): @staticmethod def login(app, username, password): - return app.post('/account/login', - data=dict(username=username, password=password), - follow_redirects=True) + return helpers.login(app, username, password) @staticmethod def logout(app): diff --git a/doajtest/unit/test_view_admin.py b/doajtest/unit/test_view_admin.py new file mode 100644 index 0000000000..2f111bb2d6 --- /dev/null +++ b/doajtest/unit/test_view_admin.py @@ -0,0 +1,37 @@ +import json + +from doajtest import helpers +from doajtest.fixtures import JournalFixtureFactory +from doajtest.fixtures.accounts import create_maned_a +from doajtest.helpers import DoajTestCase +from portality import models +from portality.util import url_for + + +class TestViewAdmin(DoajTestCase): + + def setUp(self): + super().setUp() + self.acc = create_maned_a(is_save=True) + + def test_journal_article_info(self): + journal = models.Journal( + **JournalFixtureFactory.make_journal_source() + ) + journal.save(blocking=True) + models.Journal.refresh() + + with self.app_test.test_client() as client: + resp = helpers.login(client, self.acc.email, 'password') + assert resp.status_code == 200 + + resp = client.get(url_for("admin.journal_article_info", journal_id=journal.id)) + assert resp.status_code == 200 + assert json.loads(resp.data) == {'n_articles': 0} + + def test_journal_article_info__not_found(self): + with self.app_test.test_client() as client: + helpers.login(client, self.acc.email, 'password') + + resp = client.get(url_for("admin.journal_article_info", journal_id='aksjdlaksjdlkajsdlkajsdlk')) + assert resp.status_code == 404 diff --git a/portality/view/admin.py b/portality/view/admin.py index 187aee04ee..ba440cea76 100644 --- a/portality/view/admin.py +++ b/portality/view/admin.py @@ -322,6 +322,7 @@ def journals_bulk_reinstate(): ##################################################################### @blueprint.route("/journal//article-info/", methods=["GET"]) +@login_required def journal_article_info(journal_id): j = models.Journal.pull(journal_id) if j is None: From d2f234d6676e8f1f5a7033900046e565c0bdd756 Mon Sep 17 00:00:00 2001 From: philip Date: Fri, 19 Apr 2024 12:07:45 +0100 Subject: [PATCH 08/18] wording --- portality/templates/application_form/editorial_form_fields.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portality/templates/application_form/editorial_form_fields.html b/portality/templates/application_form/editorial_form_fields.html index 0b91ff6247..f7d28bc3a2 100644 --- a/portality/templates/application_form/editorial_form_fields.html +++ b/portality/templates/application_form/editorial_form_fields.html @@ -56,7 +56,7 @@

    {{ fs.label }}

    {% set fs = formulaic_context.fieldset("seal") %} {% if fs %}

    {{ fs.label }}

    -

    The journal has fulfilled all the criteria for the Seal.

    +

    The journal may have fulfilled all the criteria for the Seal.

    {% for f in fs.fields() %} {% set field_template = f.template %} {% include field_template %} From 9532667c6405867abb01477f4119a6edcbc9c8d4 Mon Sep 17 00:00:00 2001 From: philip Date: Wed, 1 May 2024 13:15:01 +0100 Subject: [PATCH 09/18] naming --- doajtest/fixtures/accounts.py | 4 ++-- doajtest/unit/test_view_admin.py | 2 +- portality/static/vendor/edges | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doajtest/fixtures/accounts.py b/doajtest/fixtures/accounts.py index 4b974490fc..231c02ce3e 100644 --- a/doajtest/fixtures/accounts.py +++ b/doajtest/fixtures/accounts.py @@ -83,11 +83,11 @@ def create_publisher_a(): return publisher -def create_maned_a(is_save=False): +def create_maned_a(save=False): from portality import models maned = models.Account(**AccountFixtureFactory.make_managing_editor_source()) maned.set_password("password") - if is_save: + if save: maned.save(blocking=True) return maned diff --git a/doajtest/unit/test_view_admin.py b/doajtest/unit/test_view_admin.py index 2f111bb2d6..84eead5558 100644 --- a/doajtest/unit/test_view_admin.py +++ b/doajtest/unit/test_view_admin.py @@ -12,7 +12,7 @@ class TestViewAdmin(DoajTestCase): def setUp(self): super().setUp() - self.acc = create_maned_a(is_save=True) + self.acc = create_maned_a(save=True) def test_journal_article_info(self): journal = models.Journal( diff --git a/portality/static/vendor/edges b/portality/static/vendor/edges index 990f422016..9639b871ac 160000 --- a/portality/static/vendor/edges +++ b/portality/static/vendor/edges @@ -1 +1 @@ -Subproject commit 990f4220163a3e18880f0bdc3ad5c80d234d22dd +Subproject commit 9639b871acb1f6590ee78e236f2c9333479c9fe8 From e52ca45d8e4937d78e7ba1fc1c14a06fafe509c6 Mon Sep 17 00:00:00 2001 From: philip Date: Wed, 1 May 2024 13:59:18 +0100 Subject: [PATCH 10/18] use multiple checkbox for styles only --- portality/crosswalks/journal_form.py | 4 ++-- portality/forms/application_forms.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/portality/crosswalks/journal_form.py b/portality/crosswalks/journal_form.py index ecdc20c61a..91ad74a138 100644 --- a/portality/crosswalks/journal_form.py +++ b/portality/crosswalks/journal_form.py @@ -289,7 +289,7 @@ def form2admin(cls, form, obj): obj.set_editor(editor) if getattr(form, "doaj_seal", None): - obj.set_seal(form.doaj_seal.data) + obj.set_seal('y' in form.doaj_seal.data) @classmethod def bibjson2form(cls, bibjson, forminfo): @@ -457,7 +457,7 @@ def admin2form(cls, obj, forminfo): if obj.editor is not None: forminfo['editor'] = obj.editor - forminfo['doaj_seal'] = obj.has_seal() + forminfo['doaj_seal'] = ['y'] if obj.has_seal() else [] class JournalFormXWalk(JournalGenericXWalk): diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index d083a459fa..93ee44e216 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -1603,8 +1603,13 @@ class FieldDefinitions: # ~~->$ DOAJSeal:FormField~~ DOAJ_SEAL = { "name": "doaj_seal", - "label": "Award the Seal?", + "label": "The journal may have fulfilled all the criteria for the Seal.", + "multiple": True, "input": "checkbox", + "options": [ + {"display": "Award the Seal?", "value": 'y'}, + ], + "validate": [ { "only_if" : { From f415303a7e0b57a012a653c3f45fc788a186815b Mon Sep 17 00:00:00 2001 From: philip Date: Wed, 1 May 2024 14:10:46 +0100 Subject: [PATCH 11/18] update checkbox title --- portality/static/js/formulaic.js | 7 +++---- .../templates/application_form/editorial_form_fields.html | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 07d986f987..04a6b85b81 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2255,7 +2255,7 @@ var formulaic = { newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), ArticleInfo: function ({formulaic, fieldDef, args}) { - const sealSelector = '.doaj_seal__container' + const sealSelector = 'label[for=doaj_seal]'; const init = () => { const paths = window.location.pathname.split('/') @@ -2263,9 +2263,8 @@ var formulaic = { fetch(`/admin/journal/${journalId}/article-info`) .then(response => response.json()) .then(data => { - const $p = $(sealSelector).prev('p'); - const text = $p.text() - $p.text(text + `This journal has ${data.n_articles} articles in DOAJ.`) + const $ele = $(sealSelector); + $ele.text($ele.text() + `This journal has ${data.n_articles} articles in DOAJ.`) }) }; diff --git a/portality/templates/application_form/editorial_form_fields.html b/portality/templates/application_form/editorial_form_fields.html index ba8f74cab6..e567690934 100644 --- a/portality/templates/application_form/editorial_form_fields.html +++ b/portality/templates/application_form/editorial_form_fields.html @@ -56,7 +56,6 @@

    {{ fs.label }}

    {% set fs = formulaic_context.fieldset("seal") %} {% if fs %}

    {{ fs.label }}

    -

    The journal may have fulfilled all the criteria for the Seal.

    {% for f in fs.fields() %} {% set field_template = f.template %} {% include field_template %} From ee1b64226e2a5e8b32031150c30e7905cfef3e05 Mon Sep 17 00:00:00 2001 From: philip Date: Wed, 19 Jun 2024 11:09:35 +0100 Subject: [PATCH 12/18] fix for seal form field --- doajtest/fixtures/v2/common.py | 2 +- .../unit/application_processors/test_maned_journal_review.py | 4 ++-- portality/tasks/journal_bulk_edit.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doajtest/fixtures/v2/common.py b/doajtest/fixtures/v2/common.py index efa5f7367b..c550437c90 100644 --- a/doajtest/fixtures/v2/common.py +++ b/doajtest/fixtures/v2/common.py @@ -25,7 +25,7 @@ } SEAL_FORM_EXPANDED = { - "doaj_seal": False, + "doaj_seal": [], } JOURNAL_LIKE_BIBJSON = { diff --git a/doajtest/unit/application_processors/test_maned_journal_review.py b/doajtest/unit/application_processors/test_maned_journal_review.py index 07badcbabe..b62fbb146d 100644 --- a/doajtest/unit/application_processors/test_maned_journal_review.py +++ b/doajtest/unit/application_processors/test_maned_journal_review.py @@ -148,7 +148,7 @@ def test_04_maned_review_doaj_seal(self): ) # set the seal to False using the form - fc.form.doaj_seal.data = False + fc.form.doaj_seal.data = [] # run the crosswalk, don't test it at all in this test fc.form2target() @@ -162,7 +162,7 @@ def test_04_maned_review_doaj_seal(self): fc.source.set_seal(True) fc.source2form() - assert fc.form.doaj_seal.data is True + assert 'y' in fc.form.doaj_seal.data def test_05_maned_review_continuations(self): # construct it from form data (with a known source) diff --git a/portality/tasks/journal_bulk_edit.py b/portality/tasks/journal_bulk_edit.py index 3e39d4388e..0b4242adbc 100644 --- a/portality/tasks/journal_bulk_edit.py +++ b/portality/tasks/journal_bulk_edit.py @@ -123,8 +123,8 @@ def run(self): job.add_audit_message("Setting {f} to {x} for journal {y}".format(f=k, x=v, y=journal_id)) fc.form[k].data = v else: - if v: - fc.form.doaj_seal.data = v + if v or (isinstance(v, str) and v.lower() == 'y'): + fc.form.doaj_seal.data = ['y'] updated = True if note: From 56a56ea473374c0242cf48f2cd5bac7ed38b9bbe Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 8 Jul 2024 12:54:36 +0100 Subject: [PATCH 13/18] avoid send request by invalid id --- portality/static/js/formulaic.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 04a6b85b81..5da5dca982 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2255,25 +2255,24 @@ var formulaic = { newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), ArticleInfo: function ({formulaic, fieldDef, args}) { - const sealSelector = 'label[for=doaj_seal]'; - - const init = () => { - const paths = window.location.pathname.split('/') - const journalId = paths[paths.length - 1] - fetch(`/admin/journal/${journalId}/article-info`) - .then(response => response.json()) - .then(data => { - const $ele = $(sealSelector); - $ele.text($ele.text() + `This journal has ${data.n_articles} articles in DOAJ.`) - }) - }; + const $sealEle = $('label[for=doaj_seal]'); - - if ($(sealSelector).length) { - init(); - } else { + if (!$sealEle.length) { console.log('skip ArticleInfo, seal section not found') + return; + } + + const idResult = window.location.pathname.match('/journal/([a-f0-9]+)') + if (!idResult) { + console.log('skip ArticleInfo, journal id not found') + return } + const journalId = idResult[1] + fetch(`/admin/journal/${journalId}/article-info`) + .then(response => response.json()) + .then(data => { + $sealEle.text($sealEle.text() + `This journal has ${data.n_articles} articles in DOAJ.`) + }) }, From f768d1b069653ecf6ccfd8ad8d9abac742e3a843 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 8 Jul 2024 13:04:30 +0100 Subject: [PATCH 14/18] support in_doaj for count_by_issns query --- portality/models/article.py | 10 +++++++--- portality/view/admin.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/portality/models/article.py b/portality/models/article.py index d431bb5ae7..392a168514 100644 --- a/portality/models/article.py +++ b/portality/models/article.py @@ -85,8 +85,8 @@ def find_by_issns(cls, issns): return articles @classmethod - def count_by_issns(cls, issns): - q = ArticleQuery(issns=issns) + def count_by_issns(cls, issns, in_doaj=None): + q = ArticleQuery(issns=issns, in_doaj=in_doaj) return cls.hit_count(q.query()) @classmethod @@ -866,9 +866,10 @@ class ArticleQuery(object): _issn_terms = { "terms" : {"index.issn.exact" : [""]} } _volume_term = { "term" : {"bibjson.journal.volume.exact" : ""} } - def __init__(self, issns=None, volume=None): + def __init__(self, issns=None, volume=None, in_doaj=None): self.issns = issns self.volume = volume + self.in_doaj = in_doaj def query(self): q = deepcopy(self.base_query) @@ -883,6 +884,9 @@ def query(self): vq["term"]["bibjson.journal.volume.exact"] = self.volume q["query"]["bool"]["must"].append(vq) + if self.in_doaj is not None: + q["query"]["bool"]["must"].append({"term": {"admin.in_doaj": self.in_doaj}}) + return q class ArticleVolumesQuery(object): diff --git a/portality/view/admin.py b/portality/view/admin.py index ba440cea76..72c4fb6a6c 100644 --- a/portality/view/admin.py +++ b/portality/view/admin.py @@ -328,7 +328,7 @@ def journal_article_info(journal_id): if j is None: abort(404) - return {'n_articles': models.Article.count_by_issns(j.bibjson().issns())} + return {'n_articles': models.Article.count_by_issns(j.bibjson().issns(), in_doaj=True)} @blueprint.route("/journal//continue", methods=["GET", "POST"]) From 5e9f946e232d33ef89b245874985893c5ca79bf3 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 8 Jul 2024 13:08:23 +0100 Subject: [PATCH 15/18] change ArticleInfo result layout --- portality/static/js/formulaic.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 5da5dca982..2068abe12f 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2255,7 +2255,7 @@ var formulaic = { newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params), ArticleInfo: function ({formulaic, fieldDef, args}) { - const $sealEle = $('label[for=doaj_seal]'); + const $sealEle = $('label[for=doaj_seal-0]'); if (!$sealEle.length) { console.log('skip ArticleInfo, seal section not found') @@ -2271,7 +2271,7 @@ var formulaic = { fetch(`/admin/journal/${journalId}/article-info`) .then(response => response.json()) .then(data => { - $sealEle.text($sealEle.text() + `This journal has ${data.n_articles} articles in DOAJ.`) + $sealEle.text($sealEle.text() + ` (This journal has ${data.n_articles} articles in DOAJ)`) }) }, From c8f3e734e6d27721184514241b253ef83d932401 Mon Sep 17 00:00:00 2001 From: philip Date: Mon, 8 Jul 2024 13:53:09 +0100 Subject: [PATCH 16/18] support admin_site_search redirection --- portality/static/js/formulaic.js | 7 ++++++- portality/view/admin.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/portality/static/js/formulaic.js b/portality/static/js/formulaic.js index 2068abe12f..66d9188877 100644 --- a/portality/static/js/formulaic.js +++ b/portality/static/js/formulaic.js @@ -2271,7 +2271,12 @@ var formulaic = { fetch(`/admin/journal/${journalId}/article-info`) .then(response => response.json()) .then(data => { - $sealEle.text($sealEle.text() + ` (This journal has ${data.n_articles} articles in DOAJ)`) + let articleText = `(This journal has ${data.n_articles} articles in DOAJ)` + if (data.n_articles > 0) { + const articlesUrl = `/admin/journal/${journalId}/article-info/admin-site-search` + articleText = `${articleText}` + } + $sealEle.html($sealEle.text() + ` ${articleText}`) }) }, diff --git a/portality/view/admin.py b/portality/view/admin.py index 72c4fb6a6c..00d1edaec3 100644 --- a/portality/view/admin.py +++ b/portality/view/admin.py @@ -331,6 +331,21 @@ def journal_article_info(journal_id): return {'n_articles': models.Article.count_by_issns(j.bibjson().issns(), in_doaj=True)} +@blueprint.route("/journal//article-info/admin-site-search", methods=["GET"]) +@login_required +def journal_article_info_admin_site_search(journal_id): + j = models.Journal.pull(journal_id) + if j is None: + abort(404) + + issns = j.bibjson().issns() + if not issns: + abort(404) + + target_url = '/admin/admin_site_search?source={"query":{"bool":{"must":[{"term":{"admin.in_doaj":true}},{"term":{"es_type.exact":"article"}},{"query_string":{"query":"%s","default_operator":"AND","default_field":"index.issn.exact"}}]}},"track_total_hits":true}' + return redirect(target_url % issns[0].replace('-', r'\\-')) + + @blueprint.route("/journal//continue", methods=["GET", "POST"]) @login_required @ssl_required From ad0c19c54b0ab230997c2158ca6c9e212453a8c6 Mon Sep 17 00:00:00 2001 From: philip Date: Tue, 30 Jul 2024 15:10:11 +0100 Subject: [PATCH 17/18] Reverted submodule edges to develop_edges1 --- portality/static/vendor/edges | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portality/static/vendor/edges b/portality/static/vendor/edges index 9639b871ac..2ca0da93e7 160000 --- a/portality/static/vendor/edges +++ b/portality/static/vendor/edges @@ -1 +1 @@ -Subproject commit 9639b871acb1f6590ee78e236f2c9333479c9fe8 +Subproject commit 2ca0da93e7bf345a7e529d1ed056c8dd0a328b6a From c12c2ab5366d4bf09c2e3a88d571dbf50fe9f27f Mon Sep 17 00:00:00 2001 From: philip Date: Wed, 31 Jul 2024 10:09:38 +0100 Subject: [PATCH 18/18] change edges HEAD to same as develop 990f4220163a3e18880f0bdc3ad5c80d234d22dd --- portality/static/vendor/edges | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portality/static/vendor/edges b/portality/static/vendor/edges index 2ca0da93e7..990f422016 160000 --- a/portality/static/vendor/edges +++ b/portality/static/vendor/edges @@ -1 +1 @@ -Subproject commit 2ca0da93e7bf345a7e529d1ed056c8dd0a328b6a +Subproject commit 990f4220163a3e18880f0bdc3ad5c80d234d22dd