-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
190 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import app from 'flarum/admin/app'; | ||
import Alert from 'flarum/common/components/Alert'; | ||
import ExtensionPage from 'flarum/admin/components/ExtensionPage'; | ||
import humanTime from 'flarum/common/helpers/humanTime'; | ||
import extractText from 'flarum/common/utils/extractText'; | ||
import Mithril from 'mithril'; | ||
import ItemList from 'flarum/common/utils/ItemList'; | ||
// @ts-expect-error | ||
import linkify from 'linkify-lite'; | ||
|
||
export default class GeoipSettingsPage extends ExtensionPage { | ||
content() { | ||
const service = this.setting('fof-geoip.service')(); | ||
const errorTime = Number(app.data.settings[`fof-geoip.services.${service}.last_error_time`]) * 1000; | ||
const error = app.data.settings[`fof-geoip.services.${service}.error`] as string | undefined; | ||
|
||
return ( | ||
<div className="GeoipSettingsPage"> | ||
<div className="container"> | ||
<div className="GeoipSettingsTabPage GeoipSettingsPage--settings"> | ||
<div className="Form"> | ||
{error && ( | ||
<Alert className="Form-group" dismissable={false}> | ||
<b style={{ textTransform: 'uppercase', marginRight: '5px' }}>{humanTime(new Date(errorTime))}</b> | ||
{error} | ||
</Alert> | ||
)} | ||
{this.settingsItems().toArray()} | ||
<div className="Form-group">{this.submitButton()}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
settingsItems(): ItemList<Mithril.Children> { | ||
const items = new ItemList<Mithril.Children>(); | ||
|
||
items.add( | ||
'general', | ||
<div className="Section"> | ||
<h3>{app.translator.trans('fof-geoip.admin.settings.general.heading')}</h3> | ||
<p className="helpText">{app.translator.trans('fof-geoip.admin.settings.general.help')}</p> | ||
{this.generalItems().toArray()} | ||
</div> | ||
); | ||
|
||
items.add( | ||
'providers', | ||
<div className="Section"> | ||
<h3>{app.translator.trans('fof-geoip.admin.settings.providers.heading')}</h3> | ||
<p className="helpText">{app.translator.trans('fof-geoip.admin.settings.providers.help')}</p> | ||
{this.providerItems().toArray()} | ||
</div> | ||
); | ||
|
||
return items; | ||
} | ||
|
||
generalItems(): ItemList<Mithril.Children> { | ||
const items = new ItemList<Mithril.Children>(); | ||
|
||
items.add( | ||
'show-flags', | ||
this.buildSettingComponent({ | ||
setting: 'fof-geoip.showFlag', | ||
type: 'boolean', | ||
label: app.translator.trans('fof-geoip.admin.settings.show_flag_label'), | ||
help: app.translator.trans('fof-geoip.admin.settings.show_flag_help'), | ||
}) | ||
); | ||
|
||
return items; | ||
} | ||
|
||
providerItems(): ItemList<Mithril.Children> { | ||
const items = new ItemList<Mithril.Children>(); | ||
const service = this.setting('fof-geoip.service')(); | ||
|
||
items.add( | ||
'service', | ||
this.buildSettingComponent({ | ||
type: 'select', | ||
setting: 'fof-geoip.service', | ||
label: app.translator.trans('fof-geoip.admin.settings.service_label'), | ||
options: (app.data['fof-geoip.services'] as string[]).reduce((o: { [x: string]: string }, p: string) => { | ||
o[p] = extractText(app.translator.trans(`fof-geoip.admin.settings.service_${p}_label`)); | ||
return o; | ||
}, {}), | ||
required: true, | ||
help: service && m.trust(linkify(extractText(app.translator.trans(`fof-geoip.admin.settings.service_${service}_description`)))), | ||
}) | ||
); | ||
|
||
['ipdata', 'ipapi-pro', 'ipsevenex'].includes(service) && | ||
items.add( | ||
'api-key', | ||
this.buildSettingComponent({ | ||
type: 'string', | ||
setting: `fof-geoip.services.${service}.access_key`, | ||
label: app.translator.trans('fof-geoip.admin.settings.access_key_label'), | ||
required: true, | ||
}) | ||
); | ||
|
||
service === 'ipdata' && | ||
items.add( | ||
'ipdata-quota', | ||
this.buildSettingComponent({ | ||
type: 'number', | ||
setting: 'fof-geoip.services.ipdata.quota', | ||
label: app.translator.trans('fof-geoip.admin.settings.quota_label'), | ||
min: 1500, | ||
placeholder: 1500, | ||
}) | ||
); | ||
|
||
return items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import GeoipSettingsPage from './GeoipSettingsPage'; | ||
|
||
export const components = { | ||
GeoipSettingsPage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.GeoipSettingsPage { | ||
padding-top: 20px; | ||
|
||
.Button { | ||
margin-right: 10px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.GeoipSettingsTabPage { | ||
background: @control-bg; | ||
padding: 20px; | ||
border-radius: @border-radius; | ||
box-shadow: 0 2px 4px @shadow-color; | ||
|
||
h3 { | ||
color: @primary-color; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.Section { | ||
background: @body-bg; | ||
border-radius: @border-radius; | ||
box-shadow: 0 1px 3px @shadow-color; | ||
padding: 15px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.Form { | ||
.control { | ||
background: @body-bg; | ||
border: 1px solid @muted-color; | ||
color: @text-color; | ||
padding: 6px 12px; | ||
border-radius: @border-radius; | ||
} | ||
input { | ||
max-width: 300px; | ||
} | ||
} | ||
} | ||
|
||
&--settings { | ||
margin: 0 auto; | ||
|
||
@media @desktop-up { | ||
margin: 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters