Templates namespace filtering & fix

This commit is contained in:
Carlos 2019-03-20 08:57:06 +01:00
parent b6a896558e
commit 444717b4d0
5 changed files with 34 additions and 7 deletions

View file

@ -238,6 +238,7 @@ export default class CUD extends Component {
click_tracking_disabled: false, click_tracking_disabled: false,
open_tracking_disabled: false, open_tracking_disabled: false,
work_send_config_current_namespace: false, work_send_config_current_namespace: false,
work_template_current_namespace: false,
unsubscribe_url: '', unsubscribe_url: '',
@ -526,6 +527,7 @@ export default class CUD extends Component {
const currentNamespace = this.getFormValue('namespace'); const currentNamespace = this.getFormValue('namespace');
const useNamespaceSendConfig = this.getFormValue('work_send_config_current_namespace'); const useNamespaceSendConfig = this.getFormValue('work_send_config_current_namespace');
const useNamespaceTemplate = this.getFormValue('work_template_current_namespace');
for (const lstUid of lsts) { for (const lstUid of lsts) {
const prefix = 'lists_' + lstUid + '_'; const prefix = 'lists_' + lstUid + '_';
@ -569,6 +571,7 @@ export default class CUD extends Component {
} }
</div> </div>
<div className={campaignsStyles.entryContent}> <div className={campaignsStyles.entryContent}>
<CheckBox id={prefix + "work_list_current_namespace"} label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/>
{useNamespaceLists && {useNamespaceLists &&
<TableSelect id={prefix + 'list'} label={t('list')} withHeader dropdown dataUrl={`rest/users-table-byNamespace/${currentNamespace}`} columns={listsColumns} selectionLabelIndex={1} /> <TableSelect id={prefix + 'list'} label={t('list')} withHeader dropdown dataUrl={`rest/users-table-byNamespace/${currentNamespace}`} columns={listsColumns} selectionLabelIndex={1} />
} }
@ -581,7 +584,6 @@ export default class CUD extends Component {
{selectedList && this.getFormValue(prefix + 'useSegmentation') && {selectedList && this.getFormValue(prefix + 'useSegmentation') &&
<TableSelect id={prefix + 'segment'} withHeader dropdown dataUrl={`rest/segments-table/${selectedList}`} columns={segmentsColumns} selectionLabelIndex={1} /> <TableSelect id={prefix + 'segment'} withHeader dropdown dataUrl={`rest/segments-table/${selectedList}`} columns={segmentsColumns} selectionLabelIndex={1} />
} }
<CheckBox id={prefix + "work_list_current_namespace"} label={t('namespaceFiltering')} text={t('workWithCurrentNamespace')}/>
</div> </div>
} }
</div> </div>
@ -679,7 +681,13 @@ export default class CUD extends Component {
// The "key" property here and in the TableSelect below is to tell React that these tables are different and should be rendered by different instances. Otherwise, React will use // The "key" property here and in the TableSelect below is to tell React that these tables are different and should be rendered by different instances. Otherwise, React will use
// only one instance, which fails because Table does not handle updates in "columns" property // only one instance, which fails because Table does not handle updates in "columns" property
templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl='rest/templates-table' columns={templatesColumns} selectionLabelIndex={1} help={help}/>; if(useNamespaceTemplate){
templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl={`rest/templates-table-byNamespace/${currentNamespace}`} columns={templatesColumns} selectionLabelIndex={1} help={help}/>;
}
else{
templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl='rest/templates-table' columns={templatesColumns} selectionLabelIndex={1} help={help}/>;
}
} else if (!isEdit && sourceTypeKey === CampaignSource.CUSTOM_FROM_CAMPAIGN) { } else if (!isEdit && sourceTypeKey === CampaignSource.CUSTOM_FROM_CAMPAIGN) {
const campaignsColumns = [ const campaignsColumns = [
@ -753,16 +761,18 @@ export default class CUD extends Component {
<Title>{t('sendSettings')}</Title> <Title>{t('sendSettings')}</Title>
<CheckBox id="work_send_config_current_namespace" label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/>
{useNamespaceSendConfig && {useNamespaceSendConfig &&
<TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table-byNamespace/${currentNamespace}`} columns={sendConfigurationsColumns} selectionLabelIndex={1} /> <TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table-byNamespace/${currentNamespace}`} columns={sendConfigurationsColumns} selectionLabelIndex={1} />
} }
{!useNamespaceSendConfig && {!useNamespaceSendConfig &&
<TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table`} columns={sendConfigurationsColumns} selectionLabelIndex={1} /> <TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table`} columns={sendConfigurationsColumns} selectionLabelIndex={1} />
} }
<CheckBox id="work_send_config_current_namespace" label={t('namespaceFiltering')} text={t('workWithCurrentNamespace')}/>
{sendSettings} {sendSettings}
<InputField id="unsubscribe_url" label={t('customUnsubscribeUrl')}/> <InputField id="unsubscribe_url" label={t('customUnsubscribeUrl')}/>
<hr/> <hr/>
@ -770,10 +780,12 @@ export default class CUD extends Component {
<CheckBox id="open_tracking_disabled" text={t('disableOpenedTracking')}/> <CheckBox id="open_tracking_disabled" text={t('disableOpenedTracking')}/>
<CheckBox id="click_tracking_disabled" text={t('disableClickedTracking')}/> <CheckBox id="click_tracking_disabled" text={t('disableClickedTracking')}/>
{sourceEdit && <hr/> } <Title>{t('template')}</Title>
{sourceEdit} {sourceEdit}
<CheckBox id="work_template_current_namespace" label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/>
{templateEdit} {templateEdit}
<ButtonRow> <ButtonRow>

View file

@ -118,7 +118,7 @@
"blacklistedEmails": "Blacklisted Emails", "blacklistedEmails": "Blacklisted Emails",
"createRegularCampaign": "Create Regular Campaign", "createRegularCampaign": "Create Regular Campaign",
"sendSettings": "Send settings", "sendSettings": "Send settings",
"workWithCurrentNamespace": "Work with current namespace", "workWithCampaignNamespace": "Work with campaign's namespace",
"createRssCampaign": "Create RSS Campaign", "createRssCampaign": "Create RSS Campaign",
"createTriggeredCampaign": "Create Triggered Campaign", "createTriggeredCampaign": "Create Triggered Campaign",
"editRegularCampaign": "Edit Regular Campaign", "editRegularCampaign": "Edit Regular Campaign",

View file

@ -118,7 +118,7 @@
"blacklistedEmails": "Blacklisted Emails", "blacklistedEmails": "Blacklisted Emails",
"createRegularCampaign": "Crear Campaña Regular", "createRegularCampaign": "Crear Campaña Regular",
"sendSettings": "Configuración de envío", "sendSettings": "Configuración de envío",
"workWithCurrentNamespace": "Trabajar con el Espacio de nombres actual", "workWithCampaignNamespace": "Trabajar con el espacio de nombres de la campaña",
"createRssCampaign": "Create RSS Campaign", "createRssCampaign": "Create RSS Campaign",
"createTriggeredCampaign": "Create Triggered Campaign", "createTriggeredCampaign": "Create Triggered Campaign",
"editRegularCampaign": "Edit Regular Campaign", "editRegularCampaign": "Edit Regular Campaign",

View file

@ -46,6 +46,16 @@ async function listDTAjax(context, params) {
); );
} }
async function listByNamespaceDTAjax(context, params, namespaceId) {
return await dtHelpers.ajaxListWithPermissions(
context,
[{ entityTypeId: 'template', requiredOperations: ['view'] }],
params,
builder => builder.from('templates').innerJoin('namespaces', 'namespaces.id', 'templates.namespace').where('namespaces.id', namespaceId),
[ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.created', 'namespaces.name' ]
);
}
async function _validateAndPreprocess(tx, entity) { async function _validateAndPreprocess(tx, entity) {
await namespaceHelpers.validateEntity(tx, entity); await namespaceHelpers.validateEntity(tx, entity);
@ -135,6 +145,7 @@ module.exports.hash = hash;
module.exports.getByIdTx = getByIdTx; module.exports.getByIdTx = getByIdTx;
module.exports.getById = getById; module.exports.getById = getById;
module.exports.listDTAjax = listDTAjax; module.exports.listDTAjax = listDTAjax;
module.exports.listByNamespaceDTAjax = listByNamespaceDTAjax;
module.exports.create = create; module.exports.create = create;
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck; module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
module.exports.remove = remove; module.exports.remove = remove;

View file

@ -35,6 +35,10 @@ router.postAsync('/templates-table', passport.loggedIn, async (req, res) => {
return res.json(await templates.listDTAjax(req.context, req.body)); return res.json(await templates.listDTAjax(req.context, req.body));
}); });
router.postAsync('/templates-table-byNamespace/:namespaceId', passport.loggedIn, async (req, res) => {
return res.json(await templates.listByNamespaceDTAjax(req.context, req.body, castToInteger(req.params.namespaceId)));
});
router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => { router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const data = req.body; const data = req.body;
const result = await CampaignSender.testSend(req.context, data.listCid, data.subscriptionCid, data.campaignId, data.sendConfigurationId, data.html, data.text); const result = await CampaignSender.testSend(req.context, data.listCid, data.subscriptionCid, data.campaignId, data.sendConfigurationId, data.html, data.text);