mirror of
https://codeberg.org/artfulrobot/contactcats.git
synced 2025-06-26 01:48:06 +02:00
Can access entities in SK, begun new admin page
This commit is contained in:
parent
06fec5daf7
commit
4978eeb828
8 changed files with 189 additions and 191 deletions
|
@ -22,133 +22,75 @@
|
|||
// this.$onInit gets run after the this controller is called, and after the bindings have been applied.
|
||||
this.$onInit = async function() {
|
||||
ctrl.saved = false;
|
||||
const various = await crmApi4({
|
||||
settings: ["Setting", "get", { select: ["contact_categories"] }, 0],
|
||||
groups: [
|
||||
"Group",
|
||||
"get",
|
||||
{
|
||||
where: [
|
||||
["is_active", "=", 1],
|
||||
["is_hidden", "=", 0]
|
||||
],
|
||||
orderBy: { name: "ASC" }
|
||||
}
|
||||
],
|
||||
cats: [
|
||||
"OptionValue",
|
||||
"get",
|
||||
{
|
||||
select: ["value", "label"],
|
||||
where: [["option_group_id:name", "=", "contact_categories"]]
|
||||
}
|
||||
]
|
||||
});
|
||||
ctrl.catmap = [];
|
||||
if (!various.settings.value || !various.settings.value.groupIDs) {
|
||||
various.settings.value = {
|
||||
groupIDs: ["0"],
|
||||
updateAfter: 0
|
||||
};
|
||||
}
|
||||
various.settings.value.groupIDs.forEach(groupID => {
|
||||
let cat = various.cats.find(c => c.value == groupID);
|
||||
ctrl.catmap.push({
|
||||
groupID,
|
||||
name: cat ? cat.label : ""
|
||||
});
|
||||
});
|
||||
console.log({ various, catmap: ctrl.catmap });
|
||||
ctrl.groups = various.groups;
|
||||
ctrl.nameKeydown = (keyEvt, idx) => {
|
||||
if (keyEvt.key === "ArrowUp" || keyEvt.key === "ArrowDown") {
|
||||
keyEvt.preventDefault();
|
||||
keyEvt.stopPropagation();
|
||||
if (
|
||||
keyEvt.key === "ArrowUp" &&
|
||||
idx > 0 &&
|
||||
idx < ctrl.catmap.length - 1
|
||||
) {
|
||||
ctrl.catmap.splice(idx, 0, ...ctrl.catmap.splice(idx - 1, 1));
|
||||
console.log("up", { keyEvt });
|
||||
$timeout(() => keyEvt.target.focus(), 10);
|
||||
} else if (
|
||||
keyEvt.key === "ArrowDown" &&
|
||||
idx < ctrl.catmap.length - 2
|
||||
) {
|
||||
ctrl.catmap.splice(idx + 1, 0, ...ctrl.catmap.splice(idx, 1));
|
||||
console.log(
|
||||
"down",
|
||||
ctrl.catmap.map(e => e.name)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
ctrl.categoryDefinitions = null;
|
||||
ctrl.categoryDefinitions = await crmApi4("ContactCategoryDefinition", 'get', { orderBy: { label: 'ASC' }, withLabels: true });
|
||||
|
||||
$scope.$digest();
|
||||
ctrl.deleteRow = idx => {
|
||||
ctrl.catmap.splice(idx, 1);
|
||||
};
|
||||
ctrl.getGroupsFor = idx => {
|
||||
let groupsInUse = ctrl.catmap.map(c => c.groupID);
|
||||
groupsInUse.splice(idx, 1);
|
||||
return ctrl.groups.filter(
|
||||
g => !groupsInUse.includes(g.id.toString())
|
||||
);
|
||||
};
|
||||
|
||||
ctrl.save = async () => {
|
||||
console.log("save", ctrl.catmap);
|
||||
// reconstruct everything.
|
||||
// ctrl.deleteRow = idx => {
|
||||
// ctrl.catmap.splice(idx, 1);
|
||||
// };
|
||||
// ctrl.getGroupsFor = idx => {
|
||||
// let groupsInUse = ctrl.catmap.map(c => c.groupID);
|
||||
// groupsInUse.splice(idx, 1);
|
||||
// return ctrl.groups.filter(
|
||||
// g => !groupsInUse.includes(g.id.toString())
|
||||
// );
|
||||
// };
|
||||
|
||||
const optValsRecords = [];
|
||||
ctrl.catmap.forEach(r => {
|
||||
if (!r.name || r.groupID === "") {
|
||||
return;
|
||||
}
|
||||
// Do we have an option value for this group ID?
|
||||
let c = various.cats.find(cat => cat.value == r.groupID);
|
||||
if (c) {
|
||||
if (c.label != r.name) {
|
||||
optValsRecords.push({
|
||||
id: c.id,
|
||||
label: r.name
|
||||
});
|
||||
}
|
||||
} else {
|
||||
optValsRecords.push({
|
||||
label: r.name,
|
||||
value: r.groupID,
|
||||
"option_group_id:name": "contact_categories"
|
||||
});
|
||||
}
|
||||
});
|
||||
console.log("optionValue updates", optValsRecords, ctrl.catmap);
|
||||
const updates = {
|
||||
saveSetting: [
|
||||
"Setting",
|
||||
"set",
|
||||
{
|
||||
values: {
|
||||
contact_categories: {
|
||||
groupIDs: ctrl.catmap.map(i => i.groupID),
|
||||
updateAfter: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
if (optValsRecords.length) {
|
||||
updates.saveOptions = [
|
||||
"OptionValue",
|
||||
"save",
|
||||
{ records: optValsRecords }
|
||||
];
|
||||
}
|
||||
await crmApi4(updates);
|
||||
console.log("saved", updates);
|
||||
ctrl.saved = true;
|
||||
$scope.$digest();
|
||||
};
|
||||
// ctrl.save = async () => {
|
||||
// console.log("save", ctrl.catmap);
|
||||
// // reconstruct everything.
|
||||
//
|
||||
// const optValsRecords = [];
|
||||
// ctrl.catmap.forEach(r => {
|
||||
// if (!r.name || r.groupID === "") {
|
||||
// return;
|
||||
// }
|
||||
// // Do we have an option value for this group ID?
|
||||
// let c = various.cats.find(cat => cat.value == r.groupID);
|
||||
// if (c) {
|
||||
// if (c.label != r.name) {
|
||||
// optValsRecords.push({
|
||||
// id: c.id,
|
||||
// label: r.name
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// optValsRecords.push({
|
||||
// label: r.name,
|
||||
// value: r.groupID,
|
||||
// "option_group_id:name": "contact_categories"
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// console.log("optionValue updates", optValsRecords, ctrl.catmap);
|
||||
// const updates = {
|
||||
// saveSetting: [
|
||||
// "Setting",
|
||||
// "set",
|
||||
// {
|
||||
// values: {
|
||||
// contact_categories: {
|
||||
// groupIDs: ctrl.catmap.map(i => i.groupID),
|
||||
// updateAfter: 0
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// };
|
||||
// if (optValsRecords.length) {
|
||||
// updates.saveOptions = [
|
||||
// "OptionValue",
|
||||
// "save",
|
||||
// { records: optValsRecords }
|
||||
// ];
|
||||
// }
|
||||
// await crmApi4(updates);
|
||||
// console.log("saved", updates);
|
||||
// ctrl.saved = true;
|
||||
// $scope.$digest();
|
||||
// };
|
||||
};
|
||||
// this.$onChange = function(changes) {
|
||||
// // changes is object keyed by name what '<' binding changed in
|
||||
|
|
|
@ -1,51 +1,34 @@
|
|||
<div ng-if="!$ctrl.catmap">
|
||||
<div ng-if="$ctrl.categoryDefinitions === null">
|
||||
Loading...
|
||||
</div>
|
||||
<form ng-if="$ctrl.catmap" crm-ui-id-scope>
|
||||
<form ng-if="$ctrl.categoryDefinitions" crm-ui-id-scope>
|
||||
|
||||
<button ng-click="$ctrl.catmap.unshift({groupID: '', name:''})">
|
||||
<i class="crm-i fa-plus"></i> Add category
|
||||
</button>
|
||||
|
||||
<!-- I can see use of
|
||||
presentation order/grouping
|
||||
short title, "amazing"
|
||||
longer title/description. "regular givers who..."
|
||||
-->
|
||||
|
||||
<ol class="crm-catmap">
|
||||
<li ng-repeat="(idx, row) in $ctrl.catmap">
|
||||
<div class="group-input-wrapper">
|
||||
<select
|
||||
ng-if="row.groupID === '' || row.groupID > 0"
|
||||
crm-ui-select="{placeholder:'Select group',allowClear:false,label:'Group'}"
|
||||
ng-model="$ctrl.catmap[idx].groupID"
|
||||
style="width: 18rem"
|
||||
>
|
||||
<option
|
||||
ng-repeat="(grpIdx, grp) in $ctrl.getGroupsFor(idx)"
|
||||
value="{{grp.id}}"
|
||||
>{{grp.title}}</option
|
||||
>
|
||||
</select>
|
||||
</div>
|
||||
<div
|
||||
ng-if="row.groupID !== '' && row.groupID == 0"
|
||||
style="width: 18rem;display: inline-block;"
|
||||
>
|
||||
Default
|
||||
</div>
|
||||
<div class="name-input-wrapper">
|
||||
<label crm-ui-for="name{{idx}}">Label</label>
|
||||
<input
|
||||
crm-ui-id="name{{idx}}"
|
||||
type="text"
|
||||
ng-model="$ctrl.catmap[idx].name"
|
||||
ng-keydown="$ctrl.nameKeydown($event, idx)"
|
||||
/>
|
||||
<div class="hint description">
|
||||
{{ts('Use the Up/Down arrow keys to re-order')}}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<li ng-repeat="(idx, row) in $ctrl.categoryDefinitions">
|
||||
|
||||
<span style="color: {{row.color ? '#' + row.color : 'inherit'}};" >
|
||||
<i ng-if="row.icon" class="crm-i {{row.icon}}" ></i>
|
||||
{{row.label}}
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<button ng-click="$ctrl.deleteRow(idx)">
|
||||
<i class="fa-trash crm-i"></i> Delete
|
||||
</button>
|
||||
</div>
|
||||
</span>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
<button ng-click="$ctrl.save()"><i class="crm-i fa-save"></i> Save</button>
|
||||
</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue