Is there anyway of returning the options of a GoogleChart after the chart has been edited using the ChartEditor class? - google-visualization

I want to store the configuration of multiple GoogleCharts in a database and use them to create a dashboard of charts.
I currently store the options I supply for each chart in the database and have my dashboard working, displaying multiple charts.
I want to use the ChartEditor class to allow a user to amend a chart and then save the changes back to my database, so that the next time the dashboard is created, the changes are persisted.
Hence, when a user clicks on the OK button on the ChartEditor dialog, is there a way of accessing the changes to these options?

After crawling around, inspecting the ChartEditor object....
$.parseJSON(chartEditor.getChartSpecification())['options']
...returns what I'm looking for.

Just to add to Flippsie's answer, you can recreate the saved chart from the json returned from chartEditor.getChartSpecification()
var json = chartEditor.getChartSpecification(); // Or saved JSON value
var spec = JSON.parse(json);
// Get the chart details from the saved spec
var data = new google.visualization.DataTable(spec.dataTable);
var options = spec.options;
var chartType = spec.chartType || "BarChart";
// Instantiate and draw our chart, passing in some options.
window.chart = new google.visualization[chartType](document.getElementById('chart_div'));
chart.draw(data, options);

Related

Remove Oracle Apex Interactive Grid row actions

In Oracle APEX, how do I remove different actions in the interactive grid row actions?
I'd like to remove the ability to delete or add rows from both the row actions and selection actions menu.
Region Settings, Advanced, Static ID: emp
Page Settings, JavaScript, Execute when Page Loads
$(window).on("load", function() {
var actions = apex.region("emp").widget().interactiveGrid("getActions");
actions.remove("selection-add-row");
actions.remove("selection-duplicate");
actions.remove("selection-fill");
actions.remove("selection-clear");
actions.remove("selection-delete");
actions.remove("selection-copy-down");
actions.remove("selection-copy");
actions.remove("selection-refresh");
actions.remove("selection-revert");
actions.remove("single-row-view");
actions.remove("row-add-row");
actions.remove("row-duplicate");
actions.remove("row-delete");
actions.remove("row-refresh");
actions.remove("row-revert");
});
You can change "emp" to anything you'd like, change in both the static ID and javascript. Delete the lines you'd like to keep.
You can use actions.hide("{action_id}") and actions.show("{action_id}") to hide and show the row actions.

set List filters in ExtJS grid dynamically from response

I am trying to set(check) List filters of a grid column dynamically
from response.
I am able to set them but when I open the menu of the corresponding
filter and setting some other combination of data to filter
dynamically it is getting selected and later cleared.
Is the code am using below for setting filters is right?Need help.
var gridFilter = currentGrid.columns[i].filter;
gridFilter.setActive(true);
gridFilter.filter.value="SELECTED,REJECTED"; //putting static data for now
gridFilter.filter.setValue(["SELECTED", "REJECTED"]);
Best way to add and Edit filter for ExtJs is FilterBy method:
grid.getStore().filterBy(function(rec, id)) {
return (rec.get("DynamicRecName")=="DynamicFilterRecord");
}
If you want to edit existing then just remove current filters:
grid.getStore().clearFilters()

Sitecore How to get the value inside the field 'Media' of a Media Item

Update 2:
I am still fighting to get the Icon save on the server.
Here what I am doing:
Item item = Sitecore.Context.Database.GetItem(imageId);
var imageIconUrl = Sitecore.Resources.Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id32x32);
if (!string.IsNullOrEmpty(imageIconUrl))
{
// download the icon from the url
var iconFullPath = "e:\\pngIcons\\excelIcon.png";
var webClient = new System.Net.WebClient();
var downloadPath = "http://serverName/" + imageIconUrl;
webClient.DownloadFile(downloadPath, iconFullPath);
}
The variable downloadPath contains following string:
http://serverName/sitecore/shell/themes/standard/~/media/E503BA48C89B422D8400393F1C7086A7.ashx?h=32&thn=1&w=32&db=master
At the end what I can see is a png file but there is nothing in it. I also copy the string I get in variable downloadPath and pasted it in browser and I can see the Icon as follow:
Please let me know what I am doing wrong. Or How I can save the Icon. Thanks!!
Original Question:
The sitecore media item has a field "Media". I am talking about this:
I want to access this field. And the reason is:
If I access it with e.g. item.GetMediaStream() then I will get the complete file. I just want to save this little icon some how on the server. Is it possible ?
To get the icon/thumbnail you can use
var icon = Sitecore.Resources.Media.MediaManager.GetThumbnailUrl(mediaItem);
To get the url of the thumbnail.
If you want the stream of the thumbnail you need to use the MediaData object. Like this:
var mediaItem = new MediaItem(item)
var mediaData = new MediaData(mediaItem);
var iconStream = mediaData.GetThumbnailStream();
if (iconStream.Length < 0)
{
// The stream is empty, its probably a file that Sitecore can't
// generate a thumbnail for. Just use the Icon
var icon = item.Appearance.Icon;
}
This will get the icon or thumbnail of the actual media blob that is attached to the media item. If you just want the icon of the Sitecore item, then use Martins method.
If the stream is empty, then Sitecore can't generate a thumbnail for it, so you can just use the icon file for the media item template. item.Appearance.Icon
Appearance section (of Standard Template) has a field called Icon - this is where you can modify icon for the item. There is also a field called Thumbnail - your excel icon is sitting there
You can access the field programmatically, just mind that it starts with two underscores: __Icon:
var iconField = item.Fields["__Icon"];
var thumbnailField = item.Fields["__Thumbnail"];
Update: As you asked, below is the code that saves either of fields into the file on a drive. I have tested the code and confirm successfully stores icon from thumbnail field into the file:
string mediaItemPath = "/sitecore/media library/Files/ExcelFile";
string mediaFiedlName = "Thumbnail"; // also can be "__Icon"
var item = Sitecore.Context.Database.GetItem(mediaItemPath);
var iconField = item.Fields[mediaFiedlName];
if (iconField.HasBlobStream)
{
var thumb = (ImageField)iconField;
var bl = ((MediaItem)thumb.MediaItem).InnerItem.Fields["blob"];
Stream stream = bl.GetBlobStream();
byte[] buffer = new byte[8192];
using (FileStream fs = File.Create("D:\\you_file_name.ico")) // change your path
{
int length;
do
{
length = stream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, length);
}
while (length > 0);
fs.Flush();
fs.Close();
}
}
Update 2: If that does not help then I would advise to look around the way how that icon gets generated on Media field in Sitecore. In the worst case you may do the following - right click that icon and see its url. You will have something similar to what I assign to variable below:
string url = "http://test81/sitecore/shell/Applications/-/media/B4F61650CBE84EE396649602C0C48E1B.ashx?bc=White&db=master&h=128&la=en&mw=640&thn=1&vs=1&ts=b8046903-ae57-4f9d-9dd5-b626ee5eee90";
Of course your URL should have your hostname and media prefix and the rest of parameters. Then use Webclient with that modified URL:
WebClient webClient = new WebClient();
webClient.DownloadFile(url, "e:\\you_file_name.ico");
Not ideal, but may work. Note, that the code above should work in a context of already logged user, so you need to authorise you Webclient prior that (many articles on S.O. how to do that).
Please reply if that approach has worked for you (I've spent decent time writing and testing that code in debugger, so would want to know whether that helped)

Sitecore, render Item in code with personalization in mvc

My terminology might be slightly off as I am new to Sitecore mvc. I am trying to hardcode a view rendering with a hard coded datasource (I have to do it this way for other requirements) This view rendering has placeholders that are dynamically set and then personalized.
How can I trigger the ViewRendering on an item?
I've tried ItemRendering, but it doesn't seem to be picking up the stuff set up in the PageEditor.
* To be clear, the helpful posts below have the rendering working, but we do not seem to be getting the personalized datasources. *
I believe this is what you're after:
Item item = /* think you already have this */;
// Setup
var rendering = new Sitecore.Mvc.Presentation.Rendering {
RenderingType = "Item",
Renderer = new Sitecore.Mvc.Presentation.ItemRenderer.ItemRenderer {
Item = item
}
};
rendering["DataSource"] = item.ID.ToString();
// Execution
var writer = new System.IO.StringWriter();
var args = new Sitecore.Mvc.Pipelines.Response.RenderRendering(rendering, writer);
Sitecore.Mvc.Pipelines.PipelineService.Get().RunPipeline("mvc.renderRendering", args);
// Your result:
var html = writer.ToString();
You can statically bind a View Rendering using the Rendering() method of the Sitecore HTML Helper. This also works for Controller Renderings using the same method.
#Html.Sitecore().Rendering("<rendering item id>")
This method accepts an anonymous object for passing in parameters, such as the Datasource and caching options.
#Html.Sitecore().Rendering("<rendering item id>", new { DataSource = "<datasource item id>", Cacheable = true, Cache_VaryByData = true })
In your view rendering, I am assuming you have a placeholder defined along with the appropriate placeholder settings in Sitecore (If not, feel free to comment with more detail and I will update my answer).
#Html.Sitecore().Placeholder("my-placeholder")
In this case, "my-placeholder" will be handled like any other placeholder, so you will be able to add and personalize components within it from the Page Editor.

addepar ember-table: how to retrieve currently selected model data

I have hooked up the content of ember-table with an ember-data model. I'm trying to get model object underlying the row that is currently selected. I've tried using this.get('selection') but to no avail. My ultimate goal is that i have an associated edit details view in a separate view that sits next to the table (aka list view) with a router (v2) that handles the transitioning between creating new models to insert into the table and edit the currently selected model (or eventually batch edit multiple models in the table). Here's the code sample:
App.TableView = Ember.Table.TablesContainer
.extend(Ember.Table.RowSelectionMixin).extend({
selectionBinding: 'controller.selection'
});
App.TableController = Ember.Table.TableController.extend({
...
selection: null,
selectionChanged: Ember.observer(function() {
this.transitionToRoute('selectedModel.edit', this.get('selection'));
}).observes('selection'),
...
I have solved this issue. What i hadn't realized is that selection is an enumerable (i'm guessing in preparation for multiple selection which would be awesome!) In the controller:
selection: null,
selectionChanged: Ember.observer(function() {
if(this.get('selection').length) {
selection0 = this.get('selection')[0];
this.transitionToRoute('selectedModel.edit', selection0);
}
}).observes('selection'),