How can I replace the current document in a bokeh server app?
I have a previous document saved as a json_string. If I do
set_curdoc(Document.from_json_string(json_string))
this seems to properly change curdoc(), however the new document is not displayed in the browser.
I found a workaround, other places suggest to update the children of an existing layout instead of updating the whole curdoc().
I did that but I had to expand a bit to do that from a document saved in a json string.
I had to switch the document attribute of all the models from the imported document to curdoc() instead (otherwise it complains that the models belong to another document)
assuming that the document I import and the current document both have only one root:
new_doc = Document.from_json_string(json_string)
new_grid_models = collect_models(new_doc.roots[0])
for elem in new_grid_models:
try:
elem.document = curdoc()
except AttributeError:
elem._document = curdoc()
new_children = new_doc.roots[0].children
del new_doc
grid.children = new_children
After that the python callbacks need to be re-affected to the appropriate imported models.
I put up an example app here:
save_and_load app on Bitbucket
You can just clear the current document and then add a new one:
Put the whole code to create your document (bokeh app) into a function create_curdoc(). At the very end of this function you have curdoc().add_root(layout).
Call the function create_curdoc() once to create and display the document
Clear the current document with curdoc().clear()
Call the function create_curdoc() with updated data again (or another function that creates a document) to create and display the new document.
If you dont clear before calling the function again the new document will just be added at the bottom of the old one.
You could, for example, trigger the update by a button callback inside your current document.
The button setup might look like this:
def replace():
curdoc().clear()
create_curdoc()
replace_button = Button(
label="Replace Document",
button_type= "danger")
replace_button.on_click(replace)
Related
I have a two documents (a.pdf and b.pdf) in the Alfresco repository. I want to apply/upload b.pdf as a new version of a.pdf. Is there any way that I can do this using Javascript or a java code?
Thank you
Create Document, Make it Versionable, Modify It
Creates a document, makes it versionable, checks it out, modifies the content of the working copy, checks it in again and then repeats the process but checks in the document with a version history note and as a major version increment:
// create file, make it versionable
var doc = userhome.createFile('checkmeout.txt');
doc.addAspect('cm:versionable');
doc.content = 'original text';
// check it out and update content on the working copy
var workingCopy = doc.checkout();
workingCopy.content = 'updated text 1';
// check it in
doc = workingCopy.checkin();
// check it out again
workingCopy = doc.checkout();
workingCopy.content = 'updated text 2';
// check it in again, but with a version history note and as major version increment
doc = workingCopy.checkin('a history note', true);
You can take reference from below javascript api link
https://hub.alfresco.com/t5/alfresco-content-services-hub/javascript-api-cookbook/ba-p/293260
There's a version service bean that can be used to apply versioning to documents (nodes) that can be used in a custom bean. Don't forget to inject the versionService in your service-context.xml btw <property name="versionService" ref="VersionService"/>
If I remember correctly you may have to enable a versionable aspect (cm:versionable) on the node in question. If this has already been enabled then there's also the ability to view the VersionHistory for the node.
Create 2nd version and copy over with the contents of node 2.
I want to import data from a third-party module into 2sxc as content within a razor script.
IEnumerable<IDictionary<string, object>> GetData ()
{
...
}
var data = GetData();
App.Data.Create ("ContentTypeName", data);
The code above imports data into the App, but it is not linked to a content block. How do I create a new content block or access the current content block and link that data to it?
Requires a bit deeper knowledge of how Content items get attached to a module instance. There are good articles and docs on that. The key is understanding ContentGroups, so in a View, you are inside a module, and therefore your ContentGroup can be accessed like this (2sxc v9.43.x code, it may be different after ~v10.25.x):
var cGroups = App.ContentGroupManager.GetContentGroups();
var cgGuid = Dnn.Module.ModuleSettings["ToSIC_SexyContent_ContentGroupGuid"];
System.Guid cgG = Guid.Parse(cgGuid.ToString());
ContentGroup myCG = App.ContentGroupManager.GetContentGroup(cgG);
<p>My ContentGroup has #myCG.Content.Count() Entities</p>
Hopefully that gives you enough to search on and figure out from there.
Also, if you want to do it manually, that is what the Replace and Add Existing (blue 2sxc buttons) do. They show you ALL the items in the ContentType and give you to option to add an existing slot/item or replace the current item in it's slot.
How to set properties like title, author, subject for a file created with docx library for .net ?
docx
The DocX project that you provided appears to be able to easily access the metadata properties that you are referring to and can do so quite easily by using the CoreProperties property as seen below :
// Load your Document
var wordFile = Novacode.DocX.Load(#"your-docx-file-path");
// Access Metadata properties
var props = wordFile.CoreProperties;
The issue here is that this collection of properties is read only, so you won't be able to easily change them. However, you may be able to take a look at what the values look like and attempt to add one manually :
So if you wanted to update the title property (clearly named dc:title), you would simply need to add a new Core Property (via the AddCoreProperty() method) that matched that same name and then save the file to persist the changes :
// Load your Document
var wordFile = DocX.Load(#"your-docx-file-path");
// Update Metadata
wordFile.AddCoreProperty("dc:title", "Example Title");
wordFile.Save();
After doing this, you should be able to re-open the file and see that your changes reflected :
As you can see the dc:title property is now set to "Example Title" as per the example code above.
I'm doing a bit tidy of the Content Manager and have a component that won't delete (not the same as my other question).
When I try to delete the component in question I get the following error
(8004032D) This item is in use.
Unable to delete Component (tcm:4-65020).
UtilitiesBL.AssertItemCanBeDeleted
UtilitiesBL.AssertItemCanBeDeleted
ComponentBL.Delete
Component.Delete
Request.Delete
When I use the Where Used tool on the component I get no results in the "Used In" tab, one result in the "Uses" tab, the "Blueprint Hierachy" shows it is not localized in any of my three child publications and no results in the "Published To" tab.
I have had a look in the Content Manager database to see if I can spot what is going wrong but not really found anything.
Any ideas?
Thanks in advance.
It looks like the Where Used tool in R5.3 isn't working correctly. The component in question is used in 15000 other components. I found this by using the TOM API directly.
var componentID = "tcm:4-65020";
TDS.TDSE tdse = new TDS.TDSE();
var component = (TDS.Component)tdse.GetObject(componentID, TDSDefines.EnumOpenMode.OpenModeView);
var whereUsedString = component .Info.GetListUsingItems();
Now comes the task of deleting all these links...
I have written a GUI extension which adds an additional tab to many of the Item views in the SDL Tridion CME (e.g. Component, Page and Schema etc.). I have also written some JavaScript which loads that tab directly if when the view is loaded with a tab name is specified in the URL.
The result is that if a page is loaded with the tab name added as follows:
http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64&tab=InfoTab
Rather than the default of
http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64
The Info Tab will be loaded on top, instead of the General Tab. This is performed with the following code snippet and works very well:
$evt.addEventHandler($display, "start", onDisplayStarted);
// This callback is called when any view has finished loading
function onDisplayStarted() {
$evt.removeEventHandler($display, "start", onDisplayStarted);
var tabname = $url.getHashParam("tab");
if (tabname != '') {
var tabControl = $controls.getControl($("#MasterTabControl"), "Tridion.Controls.TabControl");
tabControl.selectItem(tabname);
}
}
Now I would like to make a context menu item to open items and link to the tabs using my new functionality. My first thought was to construct the Item URL myself and simply open a new window in my execute method. So I looked at the default functionality in the standard Open.prototype_execute() functionality of the GUI. This is stored in the navigation.js file of the CME, and is performed by the Tridion.Cme.Commands.Open.prototype._execute method. The code is a lot more complicated than I had anticipated as it deals with shared items, and permissions etc.
Rather than just copying all of this code to my own function, I was wondering if there is a way to elegantly extend the existing Open.prototype_execute() function and append my “&tab=MyTab” to the $cme.Popups.OPEN_ITEM_OPTIONS.URL constant for my own functions.
Any advice would be greatly appreciated.
At the end the Open command uses $config.getEditorUrl(item_type) to get the url for the item view (item_type - $const.ItemType.COMPONENT, etc). There are no extension points for this part of the functionality, but you could always try to overwrite it on your own risk.