| 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 { | 
| Akron | 386f122 | 2022-12-21 16:26:11 +0100 | [diff] [blame] | 25 | type : 'vc', | 
|  | 26 |  | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 27 | create : function (vc) { | 
|  | 28 | return Object.create(panelClass)._init(['vcinfo']).upgradeTo(this)._init(vc); | 
|  | 29 | }, | 
|  | 30 |  | 
|  | 31 | _init : function(vc){ | 
|  | 32 | this.vc = vc; | 
| Akron | 37ea119 | 2021-07-28 10:40:14 +0200 | [diff] [blame] | 33 | const actions = this.actions(); | 
| Akron | 792b1a4 | 2020-09-14 18:56:38 +0200 | [diff] [blame] | 34 | actions.add(loc.SHOW_STAT, {'cls':['statistic']}, function() { | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 35 | this.addCorpStat(); | 
|  | 36 | }.bind(this)); | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 37 | return this; | 
|  | 38 | }, | 
|  | 39 |  | 
|  | 40 |  | 
|  | 41 | /** | 
|  | 42 | * Add corpus statistic view to panel | 
|  | 43 | */ | 
|  | 44 | addCorpStat: function(){ | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 45 | const t = this; | 
|  | 46 |  | 
| hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 47 | //Refreshes corpus statistic | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 48 | if (t.statView !== undefined && t.statView.shown()){ | 
|  | 49 | let statt = t.statView.show(); | 
| hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 50 | if (statt.classList.contains('stdisabled')){ | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 51 | t.reloadCorpStat(); | 
| hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 52 | statt.classList.remove('stdisabled'); | 
|  | 53 | } | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 54 | }; | 
| hebasta | 8cab44b | 2019-12-16 13:50:32 +0100 | [diff] [blame] | 55 |  | 
|  | 56 | //Add corpus statistic | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 57 | if (t.statView === undefined || !t.statView.shown()) { | 
|  | 58 | t.statView = corpStatVClass.create(t.vc,t); | 
|  | 59 | t.add(t.statView); | 
|  | 60 | t.vc.oldvcQuery = KorAP.vc.toQuery(); | 
|  | 61 | }; | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 62 | }, | 
|  | 63 |  | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 64 | /** | 
|  | 65 | * Reload corpus statistic | 
|  | 66 | * | 
|  | 67 | */ | 
|  | 68 | reloadCorpStat: function(){ | 
|  | 69 | this.statView.close(); | 
|  | 70 | this.addCorpStat(); | 
| Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame] | 71 | } | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 72 | } | 
|  | 73 | }); |