Skip to content

Commit d83cae1

Browse files
Tomi TavelaTomi Tavela
authored andcommitted
edit web property + version update, ready to ship
1 parent 65e0733 commit d83cae1

File tree

6 files changed

+74
-61
lines changed

6 files changed

+74
-61
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sp-editor",
3-
"version": "6.0.1",
3+
"version": "6.0.2",
44
"private": true,
55
"dependencies": {
66
"@ionic/react": "^5.0.5",

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "SP Editor",
33
"homepage_url": "https://microsoftedge.microsoft.com/addons/detail/affnnhcbfmcbbdlcadgkdbfafigmjdkk",
4-
"version": "6.0.1",
4+
"version": "6.0.2",
55
"description": "Create and update SharePoint Online/SP2013/SP2016/SP2019 css/js files, inject files to web, manage web/list properties, list Webhook",
66
"icons": {
77
"16": "icons/icon16.png",

src/pages/webproperties/chrome/chrome-actions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ export async function getAllWebProperties(dispatch: Dispatch<WebPropertiesAction
7676
chrome.devtools.inspectedWindow.eval(script)
7777
}
7878

79-
export async function addWebProperty(dispatch: Dispatch<WebPropertiesActions | HomeActions>, payload: IWebProperty) {
79+
export async function addWebProperty(dispatch: Dispatch<WebPropertiesActions | HomeActions>, payload: IWebProperty, update: boolean) {
8080

8181
// show loading spinner
8282
dispatch(rootActions.setLoading(true))
8383
// close panel
84-
dispatch(actions.setNewPanel(false));
84+
if (update) {
85+
dispatch(actions.setConfirmEditDialog(true))
86+
dispatch(actions.setEditPanel(false))
87+
} else {
88+
dispatch(actions.setNewPanel(false))
89+
}
90+
8591
// add listener to receive the results from inspected page
8692
(window as any).port.onMessage.addListener(async function addWebPropertyCallback(message: any) {
8793

@@ -105,7 +111,7 @@ export async function addWebProperty(dispatch: Dispatch<WebPropertiesActions | H
105111
// set success message
106112
dispatch(rootActions.setAppMessage({
107113
showMessage: true,
108-
message: 'Web Property added succesfully!',
114+
message: !update ? 'Web Property added succesfully!' : 'Web Property updated succesfully!',
109115
color: MessageBarColors.success,
110116
}))
111117
} else {

src/pages/webproperties/chrome/createwebproperty.ts

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,48 +83,51 @@ export function createWebProperty(...args: any) {
8383
body: payload,
8484
})
8585
.then((r) => {
86-
if (indexed) {
87-
$pnp.sp.web.allProperties.select('vti_indexedpropertykeys')().then(result => {
88-
89-
const allProps = []
90-
for (let prop in result) {
91-
if (prop && prop !== 'odata.metadata' && prop !== '__metadata' && prop !== 'odata.editLink' && prop !== 'odata.id' && prop !== 'odata.type') {
92-
93-
const re = /_x.*?_/g
94-
const found = prop.match(re)
95-
const origKey = prop
96-
97-
if (found !== null)
98-
for (const g in found) {
99-
if (g) {
100-
const unesc = found[g].replace('_x', '%u').replace('_', '')
101-
prop = prop.replace(found[g], unescape(unesc))
102-
}
86+
// if (indexed) {
87+
$pnp.sp.web.allProperties.select('vti_indexedpropertykeys')().then(result => {
88+
89+
const allProps = []
90+
for (let prop in result) {
91+
if (prop && prop !== 'odata.metadata' && prop !== '__metadata' && prop !== 'odata.editLink' && prop !== 'odata.id' && prop !== 'odata.type') {
92+
93+
const re = /_x.*?_/g
94+
const found = prop.match(re)
95+
const origKey = prop
96+
97+
if (found !== null)
98+
for (const g in found) {
99+
if (g) {
100+
const unesc = found[g].replace('_x', '%u').replace('_', '')
101+
prop = prop.replace(found[g], unescape(unesc))
103102
}
104-
allProps.push({ key: prop.replace(/OData_/g, ''), value: result[origKey] })
105-
}
103+
}
104+
allProps.push({ key: prop.replace(/OData_/g, ''), value: result[origKey] })
106105
}
107-
108-
const bytes = []
109-
for (let i = 0; i < key.length; ++i) {
110-
bytes.push(key.charCodeAt(i))
111-
bytes.push(0)
112-
}
113-
114-
const b64encoded = window.btoa(String.fromCharCode.apply(null, bytes))
115-
let newIndexValue = ''
116-
117-
const propertyBag = allProps.find((el) => el.key === 'vti_indexedpropertykeys')
118-
119-
// tslint:disable-next-line:prefer-conditional-expression
120-
if (propertyBag && propertyBag.value
121-
&& propertyBag.value.length > 0) {
122-
newIndexValue = propertyBag.value.indexOf(`${b64encoded}|`) === -1 ? `${propertyBag.value}${b64encoded}|` : propertyBag.value
123-
} else {
124-
newIndexValue = `${b64encoded}|`
106+
}
107+
108+
const bytes = []
109+
for (let i = 0; i < key.length; ++i) {
110+
bytes.push(key.charCodeAt(i))
111+
bytes.push(0)
112+
}
113+
114+
const b64encoded = window.btoa(String.fromCharCode.apply(null, bytes))
115+
let newIndexValue = ''
116+
117+
const propertyBag = allProps.find((el) => el.key === 'vti_indexedpropertykeys')
118+
119+
if (indexed) {
120+
newIndexValue = propertyBag && propertyBag.value && propertyBag.value.length > 0 ?
121+
propertyBag.value.indexOf(`${b64encoded}|`) === -1 ? `${propertyBag.value}${b64encoded}|` : propertyBag.value
122+
: newIndexValue = `${b64encoded}|`
123+
} else {
124+
if (propertyBag && propertyBag.value && propertyBag.value.length > 0) {
125+
newIndexValue = propertyBag.value
126+
newIndexValue = newIndexValue.replace(b64encoded + '|', '')
125127
}
128+
}
126129

127-
const payload2 = `
130+
const payload2 = `
128131
<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SPEditor">
129132
<Actions>
130133
<Method Name="SetFieldValue" Id="9" ObjectPathId="4">
@@ -141,18 +144,18 @@ export function createWebProperty(...args: any) {
141144
</ObjectPaths>
142145
</Request>`
143146

144-
client.post(endpoint, {
145-
headers: {
146-
Accept: '*/*',
147-
'Content-Type': 'text/xml;charset="UTF-8"',
148-
'X-Requested-With': 'XMLHttpRequest',
149-
},
150-
body: payload2,
151-
}).then(postMessage)
152-
})
153-
} else {
154-
postMessage()
155-
}
147+
client.post(endpoint, {
148+
headers: {
149+
Accept: '*/*',
150+
'Content-Type': 'text/xml;charset="UTF-8"',
151+
'X-Requested-With': 'XMLHttpRequest',
152+
},
153+
body: payload2,
154+
}).then(postMessage)
155+
})
156+
/* } else {
157+
postMessage()
158+
}*/
156159
})
157160
})
158161
})

src/pages/webproperties/components/editpanel.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IRootState } from '../../../store'
1717
// mport { updateScriptLink } from '../../../store/scriptlinks/async-actions'
1818
import { setConfirmEditDialog, setEditPanel, setSelectedItem } from '../../../store/webproperties/actions'
1919
import { IWebProperty } from '../../../store/webproperties/types'
20+
import { addWebProperty } from '../chrome/chrome-actions'
2021

2122
const WebPropertiesEditPanel = () => {
2223

@@ -74,14 +75,17 @@ const WebPropertiesEditPanel = () => {
7475
rows={5}
7576
autoAdjustHeight
7677
onChange={(event, newValue?: string) => {
77-
setEditItem({ ...selectedItem, value: newValue ? newValue : '' })
78+
dispatch(setSelectedItem({ ...selectedItem, value: newValue ? newValue : '' }))
7879
}}
7980
/>
8081
<Toggle
8182
label='Indexed'
82-
defaultChecked={selectedItem.indexed}
83+
checked={selectedItem.indexed}
8384
onText='Yes'
8485
offText='No'
86+
onChange={(event, checked?: boolean) => {
87+
dispatch(setSelectedItem({ ...selectedItem, indexed: checked ? true : false }))
88+
}}
8589
/>
8690

8791
</Stack>
@@ -92,16 +96,16 @@ const WebPropertiesEditPanel = () => {
9296
dialogContentProps={{
9397
showCloseButton: true,
9498
type: DialogType.normal,
95-
title: 'Edit ScriptLink',
99+
title: 'Edit Web Property',
96100
closeButtonAriaLabel: 'Cancel',
97-
subText: `Sure you want to edit the selected scriptlink?`,
101+
subText: `Sure you want to edit the selected web property?`,
98102
}}
99103
modalProps={{
100104
isDarkOverlay: isDark,
101105
}}
102106
>
103107
<DialogFooter>
104-
<PrimaryButton onClick={() => {/*updateScriptLink(dispatch, selectedItem!)*/ }} text='Update' />
108+
<PrimaryButton onClick={() => { addWebProperty(dispatch, selectedItem!, true) }} text='Update' />
105109
<DefaultButton onClick={() => { dispatch(setConfirmEditDialog(true)) }} text='Cancel' />
106110
</DialogFooter>
107111
</Dialog>

src/pages/webproperties/components/newpanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const WebPropertiesNewPanel = () => {
4343
<PrimaryButton
4444
onClick={() => {
4545
if (newItem && newItem.key && newItem.key.length > 0) {
46-
addWebProperty(dispatch, newItem)
46+
addWebProperty(dispatch, newItem, false)
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)