Skip to content

Commit

Permalink
chore: final test
Browse files Browse the repository at this point in the history
  • Loading branch information
Burial0268 committed Jul 5, 2023
1 parent 1bdd549 commit 97e4447
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 46 deletions.
5 changes: 4 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
->addInclude('posts.userip_info'),

(new Extend\Settings())
->serializeToForum('GbclUserIp','gbcl-userip')
->serializeToForum('BadgeOptions','gbcl-userip.badgeOptions')
->serializeToForum('HoverOptions','gbcl-userip.hoverOptions')
->default('gbcl-userip.hoverOptions','countryCode|region|isp')
->default('gbcl-userip.badgeOptions','countryCode|region|isp')
->default('gbcl-userip.service', 'ovincApi'),

];
10 changes: 5 additions & 5 deletions js/src/admin/components/ExtensionSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

import { NestedStringArray } from '@askvortsov/rich-icu-message-formatter'
import {NestedStringArray} from '@askvortsov/rich-icu-message-formatter'
import app from 'flarum/admin/app'
import ExtensionPage from 'flarum/admin/components/ExtensionPage'
import extractText from 'flarum/common/utils/extractText'
Expand Down Expand Up @@ -66,20 +66,20 @@ export default class GeoIPSettingsPage extends ExtensionPage {
<div className='Form-group'>
{this.buildSettingComponent({
type: 'text',
setting: `gbcl-userip.service.badgeOptions`,
setting: `gbcl-userip.badgeOptions`,
label: app.translator.trans(
'gbcl-userip.admin.service.badgeOptionsLabel'
),
help: `Use '|' to split. Available Options: ${serviceAllAttrs.toString()}`,
help: `${app.translator.trans('gbcl-userip.admin.service.options_label_help')} ${serviceAllAttrs.toString()}`,
})}

{this.buildSettingComponent({
type: 'text',
setting: `gbcl-userip.service.hoverOptions`,
setting: `gbcl-userip.hoverOptions`,
label: app.translator.trans(
'gbcl-userip.admin.service.hoverOptionsLabel'
),
help: `Use '|' to split. Available Options: ${serviceAllAttrs.toString()}`,
help: `${app.translator.trans('gbcl-userip.admin.service.options_label_help')} ${serviceAllAttrs.toString()}`,
})}
</div>
{this.submitButton()}
Expand Down
6 changes: 3 additions & 3 deletions js/src/forum/ProcessData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { NestedStringArray } from '@askvortsov/rich-icu-message-formatter'
import IPInfo from './Model/IPInfo'
import app from 'flarum/forum/app'

export type Data = {
countryCode: NestedStringArray
Expand Down Expand Up @@ -39,12 +40,11 @@ export default class ProcessData {

process(errorNotice: NestedStringArray) {
const elements = {} as Data
let errorCount = 0
const badgeAttrs = app.forum.attribute('BadgeOptions')

for (const [key, value] of Object.entries(this.data)) {
if (errorCount > 2) return false
if (badgeAttrs == null) return false

errorCount = value ? errorCount : ++errorCount
elements[key] = value || errorNotice
}

Expand Down
52 changes: 24 additions & 28 deletions js/src/forum/components/GeoIpToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,50 @@
* file that was distributed with this source code.
*/

import Component, { ComponentAttrs } from 'flarum/common/Component'
import { Data } from '../ProcessData'
import Component, {ComponentAttrs} from 'flarum/common/Component'
import {Data} from '../ProcessData'
import app from 'flarum/forum/app'
import Tooltip from 'flarum/common/components/Tooltip'

const BADGE_OPTIONS_KEY = 'badgeOptions'
const HOVER_OPTIONS_KEY = 'hoverOptions'
const BADGE_OPTIONS_KEY = 'BadgeOptions'
const HOVER_OPTIONS_KEY = 'HoverOptions'

export interface GeoIpBarAttrs extends ComponentAttrs {
elements: Data
}

interface Settings {
service: {
[BADGE_OPTIONS_KEY]: string
[HOVER_OPTIONS_KEY]: string
}
}

enum Service {
Badge,
Hover,
}

export default class GeoIpToolBar<
CustomAttrs extends GeoIpBarAttrs = GeoIpBarAttrs
> extends Component<CustomAttrs> {
view() {
const settings = JSON.parse(app.forum.attribute('GbclUserIp')) as Settings

return (
<Tooltip text={this.getOptions(Service.Hover, settings)}>
const hover = this.getOptions(HOVER_OPTIONS_KEY);
const badge = this.getOptions(BADGE_OPTIONS_KEY);

return hover ? (
<Tooltip text={hover}>
<div className='userIp-container'>
<div className='ip-locate' id='info-country'>
{`${this.getOptions(Service.Badge, settings)}`}
{badge}
</div>
</div>
</Tooltip>
)
) : (
<div className='userIp-container'>
<div className='ip-locate' id='info-country'>
{badge}
</div>
</div>
);
}

getOptions(service: Service, settings: Settings) {
const { elements } = this.attrs
getOptions(settings: string): string | false {
const {elements} = this.attrs
const data: string = app.forum.attribute(settings)
if (!data) return false;

return settings.service[
service === Service.Badge ? BADGE_OPTIONS_KEY : HOVER_OPTIONS_KEY
]
return data
.split('|')
.map(value => `${elements[value]} |`)
.map(value => `${elements[value]}`)
.join(' | ')
}
}
10 changes: 1 addition & 9 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gbcl-userip:
label: Service
badgeOptionsLabel: Badge Options
hoverOptionsLabel: Hover Options
options_label_help: Use '|' to split. Available Options:

ipsb:
label: IP.SB
Expand All @@ -18,12 +19,3 @@ gbcl-userip:
ovincApi:
label: Ovinc Inner Api
description: Inner Api for Customer

areaCode: Area Code
backboneIsp: Backbone ISP
district: District
province: Province
isp: ISP
countryCode: Country Code
region: Region
city: City
3 changes: 3 additions & 0 deletions resources/locale/zh-Hans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ gbcl-userip:

service:
label: 服务
badgeOptionsLabel: 基本显示标签选项
hoverOptionsLabel: 更多显示标签选项
options_label_help: 多个参数请使用‘|’ 分割。 支持参数:

ipsb:
label: IP.SB
Expand Down

0 comments on commit 97e4447

Please sign in to comment.