-
Notifications
You must be signed in to change notification settings - Fork 503
issue/8979 #2898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
issue/8979 #2898
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,244 @@ | ||
| 'use strict'; | ||
|
|
||
| const PromiseManager = require('../../core/promiseManager'); | ||
| const { callApi } = require('../../util/common'); | ||
|
|
||
| Entry.EXPANSION_BLOCK.disasterAlert = { | ||
| name: 'disasterAlert', | ||
| imageName: 'disasterAlert.png', | ||
| title: { | ||
| ko: '재난문자', | ||
| en: 'Disaster alert', | ||
| }, | ||
| titleKey: 'template.disaster_alert_title_text', | ||
| description: Lang.Msgs.expansion_disasterAlert_description, | ||
| descriptionKey: 'Msgs.expansion_disasterAlert_description', | ||
| isInitialized: false, | ||
| init() { | ||
| if (this.isInitialized) { | ||
| return; | ||
| } | ||
| Entry.EXPANSION_BLOCK.disasterAlert.isInitialized = true; | ||
| }, | ||
| api: '/api/expansionBlock/disasterAlert', | ||
| apiType: '01', | ||
| }; | ||
|
|
||
| const EMERGENCY_CATEGORY_MAP = { | ||
| info: Lang.Blocks.disasterAlertTypeInfo, | ||
| exigency: Lang.Blocks.disasterAlertTypeExigency, | ||
| urgency: Lang.Blocks.disasterAlertTypeUrgency, | ||
| }; | ||
|
|
||
| const getDisasterAlert = (params, defaultValue) => { | ||
| const now = new Date(); | ||
| const hour = now.getHours(); | ||
| const day = now.getDay(); | ||
| const key = `disasterAlert-${day}-${hour}`; | ||
| const promiseManager = new PromiseManager(); | ||
| const job = promiseManager | ||
| // eslint-disable-next-line new-cap | ||
| .Promise((resolve) => { | ||
| callApi(key, { | ||
| url: `${Entry.EXPANSION_BLOCK.disasterAlert.api}`, | ||
| }) | ||
| .then((result) => { | ||
| if (result) { | ||
| let items = result?.data?.body || []; | ||
| const category = EMERGENCY_CATEGORY_MAP?.[params?.category]; | ||
| if (category) { | ||
| items = items.filter((item) => item.EMRG_STEP_NM === category); | ||
| } | ||
| switch (params.command) { | ||
| case 'count': | ||
| return resolve(items?.length || defaultValue || 0); | ||
| case 'get': | ||
| const result = items?.[params?.index - 1]?.[params.option]; | ||
| if (!result) { | ||
| return resolve(defaultValue); | ||
| } | ||
| if (params?.option === 'REG_YMD') { | ||
| return resolve(new Date(result).toLocaleString()); | ||
| } | ||
| return resolve(result); | ||
| case 'exist': | ||
| return resolve(items?.length > 0); | ||
| default: | ||
| return resolve(defaultValue); | ||
| } | ||
| } | ||
| return resolve(defaultValue); | ||
| }) | ||
| .catch(() => resolve(defaultValue)); | ||
| }) | ||
| .catch(() => defaultValue); | ||
|
|
||
| return job; | ||
| }; | ||
|
|
||
| Entry.EXPANSION_BLOCK.disasterAlert.getBlocks = function () { | ||
| // 전체, 안전안내, 긴급재난, 위급재난 | ||
| const DisasterAlertCategory = { | ||
| type: 'Dropdown', | ||
| options: [ | ||
| [Lang.Blocks.disasterAlertTypeAll, 'all'], | ||
| [Lang.Blocks.disasterAlertTypeInfo, 'info'], | ||
| [Lang.Blocks.disasterAlertTypeExigency, 'exigency'], | ||
| [Lang.Blocks.disasterAlertTypeUrgency, 'urgency'], | ||
| ], | ||
| value: 'all', | ||
| fontSize: 11, | ||
| bgColor: EntryStatic.colorSet.block.darken.EXPANSION, | ||
| arrowColor: EntryStatic.colorSet.common.WHITE, | ||
| }; | ||
| // 내용, 수신지역, 긴급단계, 재해구분, 생성일시 | ||
| const DisasterAlertOptions = { | ||
| type: 'Dropdown', | ||
| options: [ | ||
| [Lang.Blocks.disasterAlertContents, 'MSG_CN'], | ||
| [Lang.Blocks.disasterAlertRegeion, 'RCPTN_RGN_NM'], | ||
| [Lang.Blocks.disasterAlertStep, 'EMRG_STEP_NM'], | ||
| [Lang.Blocks.disasterAlertDisaster, 'DST_SE_NM'], | ||
| [Lang.Blocks.disasterAlertRegisterDate, 'REG_YMD'], | ||
| ], | ||
| value: 'MSG_CN', | ||
| fontSize: 11, | ||
| bgColor: EntryStatic.colorSet.block.darken.EXPANSION, | ||
| arrowColor: EntryStatic.colorSet.common.WHITE, | ||
| }; | ||
|
|
||
| return { | ||
| disaster_alert_title: { | ||
| template: '%1', | ||
| skeleton: 'basic_text', | ||
| color: EntryStatic.colorSet.common.TRANSPARENT, | ||
| params: [ | ||
| { | ||
| type: 'Text', | ||
| text: Lang.template.disaster_alert_title_text, | ||
| color: EntryStatic.colorSet.common.TEXT, | ||
| align: 'center', | ||
| }, | ||
| ], | ||
| def: { | ||
| type: 'disaster_alert_title', | ||
| }, | ||
| class: 'disasterAlert', | ||
| isNotFor: ['disasterAlert'], | ||
| events: {}, | ||
| }, | ||
| count_disaster_alert: { | ||
| color: EntryStatic.colorSet.block.default.EXPANSION, | ||
| outerLine: EntryStatic.colorSet.block.darken.EXPANSION, | ||
| skeleton: 'basic_string_field', | ||
| statements: [], | ||
| params: [DisasterAlertCategory], | ||
| events: {}, | ||
| def: { | ||
| params: [DisasterAlertCategory.value], | ||
| type: 'count_disaster_alert', | ||
| }, | ||
| pyHelpDef: { | ||
| params: ['A&value'], | ||
| type: 'count_disaster_alert', | ||
| }, | ||
| paramsKeyMap: { | ||
| CATEGORY: 0, | ||
| }, | ||
| class: 'disasterAlert', | ||
| isNotFor: ['disasterAlert'], | ||
| func(sprite, script) { | ||
| const category = script.getField('CATEGORY', script); | ||
| return getDisasterAlert( | ||
| { | ||
| command: 'count', | ||
| category, | ||
| }, | ||
| 0 | ||
| ); | ||
| }, | ||
| syntax: { | ||
| js: [], | ||
| py: [], | ||
| }, | ||
| }, | ||
| get_disaster_alert: { | ||
| color: EntryStatic.colorSet.block.default.EXPANSION, | ||
| outerLine: EntryStatic.colorSet.block.darken.EXPANSION, | ||
| skeleton: 'basic_string_field', | ||
| statements: [], | ||
| params: [ | ||
| DisasterAlertCategory, | ||
| { | ||
| type: 'Block', | ||
| accept: 'string', | ||
| defaultType: 'number', | ||
| }, | ||
| DisasterAlertOptions, | ||
| ], | ||
| events: {}, | ||
| def: { | ||
| params: [DisasterAlertCategory.value, null, DisasterAlertOptions.value], | ||
| type: 'get_disaster_alert', | ||
| }, | ||
| pyHelpDef: { | ||
| params: ['A&value', 'B&value', 'C&value'], | ||
| type: 'get_disaster_alert', | ||
| }, | ||
| paramsKeyMap: { | ||
| CATEGORY: 0, | ||
| NUMBER: 1, | ||
| OPTION: 2, | ||
| }, | ||
| class: 'disasterAlert', | ||
| isNotFor: ['disasterAlert'], | ||
| func(sprite, script) { | ||
| const number = script.getStringValue('NUMBER', script); | ||
| const category = script.getField('CATEGORY', script); | ||
| const option = script.getField('OPTION', script); | ||
| return getDisasterAlert({ | ||
| command: 'get', | ||
| category, | ||
| index: number, | ||
| option, | ||
| }); | ||
| }, | ||
| syntax: { | ||
| js: [], | ||
| py: [], | ||
| }, | ||
| }, | ||
| check_disaster_alert: { | ||
| color: EntryStatic.colorSet.block.default.EXPANSION, | ||
| outerLine: EntryStatic.colorSet.block.darken.EXPANSION, | ||
| skeleton: 'basic_boolean_field', | ||
| statements: [], | ||
| params: [DisasterAlertCategory], | ||
| events: {}, | ||
| def: { | ||
| params: [DisasterAlertCategory.value], | ||
| type: 'check_disaster_alert', | ||
| }, | ||
| pyHelpDef: { | ||
| params: ['B&value', null], | ||
| type: 'check_disaster_alert', | ||
| }, | ||
| paramsKeyMap: { | ||
| CATEGORY: 0, | ||
| }, | ||
| class: 'disasterAlert', | ||
| isNotFor: ['disasterAlert'], | ||
| async func(sprite, script) { | ||
| const category = script.getField('CATEGORY', script); | ||
| return getDisasterAlert({ | ||
| command: 'exist', | ||
| category, | ||
| }); | ||
| }, | ||
| syntax: { | ||
| js: [], | ||
| py: [], | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.