hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 1 | /** |
| 2 | * The vc info panel |
| 3 | * |
| 4 | * The vc info panel displays information about the virtual corpus, |
| 5 | * for example the corpus statistic |
| 6 | * |
| 7 | * @author Helge Stallkamp |
| 8 | */ |
| 9 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 10 | "use strict"; |
| 11 | |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 12 | define([ |
| 13 | 'panel', |
Akron | aa61322 | 2019-11-19 13:57:12 +0100 | [diff] [blame] | 14 | 'view/vc/corpstatv' |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 15 | ], function (panelClass, corpStatVClass) { |
| 16 | |
| 17 | const d = document; |
| 18 | |
| 19 | // Localization values |
| 20 | const loc = KorAP.Locale; |
| 21 | loc.SHOW_STAT= loc.SHOW_STAT || 'Statistics'; |
| 22 | loc.VERB_SHOWSTAT = loc.VERB_SHOWSTAT || 'Corpus Statistics'; |
| 23 | |
| 24 | return { |
| 25 | create : function (vc) { |
| 26 | return Object.create(panelClass)._init(['vcinfo']).upgradeTo(this)._init(vc); |
| 27 | }, |
| 28 | |
| 29 | _init : function(vc){ |
| 30 | this.vc = vc; |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 31 | const actions = this.actions; |
Akron | 792b1a4 | 2020-09-14 18:56:38 +0200 | [diff] [blame] | 32 | actions.add(loc.SHOW_STAT, {'cls':['statistic']}, function() { |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 33 | this.addCorpStat(); |
| 34 | }.bind(this)); |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 35 | return this; |
| 36 | }, |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Add corpus statistic view to panel |
| 41 | */ |
| 42 | addCorpStat: function(){ |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 43 | const t = this; |
| 44 | |
hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 45 | //Refreshes corpus statistic |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 46 | if (t.statView !== undefined && t.statView.shown()){ |
| 47 | let statt = t.statView.show(); |
hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 48 | if (statt.classList.contains('stdisabled')){ |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 49 | t.reloadCorpStat(); |
hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 50 | statt.classList.remove('stdisabled'); |
| 51 | } |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 52 | }; |
hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 53 | |
| 54 | //Add corpus statistic |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 55 | if (t.statView === undefined || !t.statView.shown()) { |
| 56 | t.statView = corpStatVClass.create(t.vc,t); |
| 57 | t.add(t.statView); |
| 58 | t.vc.oldvcQuery = KorAP.vc.toQuery(); |
| 59 | }; |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 60 | }, |
| 61 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 62 | /** |
| 63 | * Reload corpus statistic |
| 64 | * |
| 65 | */ |
| 66 | reloadCorpStat: function(){ |
| 67 | this.statView.close(); |
| 68 | this.addCorpStat(); |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 69 | } |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 70 | } |
| 71 | }); |