Skip to content
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

issue/8979 #2898

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extern/util/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ EntryStatic.getAllBlocks = function () {
'get_social_disaster_guideline',
'count_safety_accident_guideline',
'get_safety_accident_guideline',
'disaster_alert_title',
'count_disaster_alert',
'get_disaster_alert',
'check_disaster_alert',
],
},
{
Expand Down
Binary file added images/hardware/disasterAlert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/class/Expansion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../playground/blocks/block_expansion_festival';
import '../playground/blocks/block_expansion_behaviorconduct_disaster';
import '../playground/blocks/block_expansion_behaviorconduct_lifesafety';
import '../playground/blocks/block_expansion_emergencyActionGuidelines';
import '../playground/blocks/block_expansion_disasterAlert';

export default class Expansion {
constructor(playground) {
Expand Down
244 changes: 244 additions & 0 deletions src/playground/blocks/block_expansion_disasterAlert.js
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];
leunge marked this conversation as resolved.
Show resolved Hide resolved
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: [],
},
},
};
};
Loading