IT Hit WebDAV Ajax Browser Custom Columns - ithit-ajax-file-browser

I am looking at a trial of the Ajax Browser Control by ItHit. So far it seems to be pretty responsive when it comes to pulling files across http protocol.
What I want to do at this point is have the details view pull custom properties from my excel workbooks. What is the most efficient way to connect my C# code that gets the custom properties to the Ajax control to display the correct values?

The easiest way to create a custom column is to return custom property from a WebDAV server. In the example below the server returns price in PricesNs:RetailPrice property.
On a client side you will define a custom column and specify custom property name and namespace:
{
Id: 'MyColumn1',
CustomPropertyName: 'RetailPrice',
CustomPropertyNamespace: 'PricesNs',
Text: 'Retail Price',
Width: '150px'
}
Another approach is to return an HTML from a Formatter function specified for column. You have a full control over what is being displayed in this case.
You can find more details and an example in this article: http://www.webdavsystem.com/ajaxfilebrowser/programming/grids_customization/
In case your WebDAV server is running on IT Hit WebDAV Server Engine, to return the requested property, you must implement IHierarchyItem.GetProperties method (or its asynchronous counterpart):
public IEnumerable<PropertyValue> GetProperties(IList<PropertyName> names, bool allprop)
{
if (allprop)
{
return getPropertyValues();
}
List<PropertyValue> propVals = new List<PropertyValue>();
foreach(PropertyName propName in names)
{
if( (propName.Namespace == "PricesNs") && (propName.Name == "RetailPrice") )
{
// Depending on the item you will return a different price,
// but here for the sake of simplicity we return one price regerdless of the item
propVals.Add(new PropertyValue(propName, "100"));
}
else
{
...
}
}
return propVals;
}

Related

Dynamic tab view with multiple API calls using Flutter

I want to create a Flutter tab view, tab count and content must be based on the multiple API calls.
There is 3 section in each tab and each section get data from a separate API.
What is the best method to create a solution? Bloc is the best way to manage the state.
I tried to implement a CustomTabView and set tab data but I'm facing various issues and wired tab combinations. Please help me to solve this problem.
Thank you
This is a general question and doesn't have debug details, so the answer can seem a bit dumb.
Anyway,
The best case is to have a separate block for each section.
But you can also have all requests in one block. It is not recommended at all, but I will explain the method.
For call Multi api in one bloC:
when you use the state manager bloC , you have a method named mapEventToState that calls a second method of Stream type according to your request.
It is in this method that you return the State. In order to call several APIs, you need to define a dynamic variable here for each one. Then connect to each API here and fill these variables with the corresponding response.
To return the result, it is better if all variables containing the response containing statusCode were successful, then the state of this bloC should be succeeded.
...
#override
Stream<MyBlocState> mapEventToState(MyBlocEvent event) async* {
if (event is CallTheAPIsEvent) {
yield ApisHaveNeedCalles();
}
// second method of Stream
Stream<MyBlocState> ApisHaveNeedCalles() {
var resultApi1;
var resultApi2;
var resultApi3;
try {
resultApi1 = _repository.getAPI1();
resultApi2 = _repository.getAPI2();
resultApi3 = _repository.getAPI3();
} catch (e) {
yield ErrorState();
}
if (resultApi1 != null && resultApi2 != null && resultApi13 != null) {
yield SuccessState(resultList: [resultApi1, resultApi2, resultApi3 ]);
}
// more event handling
}
...

UIActivityViewController "Save to Files" saves multiple files when only 1 file is required

My app is able to provide a variety of UIActivityItem types (text, data, rich text, print page renderer, etc) for sharing for a variety of purposes, including printing, copy/paste, and saving as a file. For the purpose of copy/paste, it needs to include plain text, attributed string, data (JSON Data) and JSON string).
However, because several data types are provided, the UIActivityViewController's "Save to Files" option results in several files being saved - one for each of the item types that can be saved as a file.
If I reduce it to just one UIActivityItem, then copy/paste functionality is severely reduced so that it would not work with all of the various different pasteboard types it should (eg, my app's custom JSON data format AND with plain text AND attributed string).
So I'm attempting to use a UIActivityItemProvider subclass to overcome the issue, but I still cannot figure out how to get only one file to be saved, instead of multiple files (one for each item type). Is this even possible?
Relevant parts of my UIActivityItemProvider subclass are below.
(Note that I'm using multiple instances of a single subclass for this, but the same problem would occur with using different subclasses.)
class RatsActivityItemProvider: UIActivityItemProvider {
var rats: [Rat]
init(placeholderItem: Any, rats: [Rat]) {
RatsActivityItemProvider.selectedOption = nil
self.rats = rats
super.init(placeholderItem: placeholderItem)
}
class func allProviders(forRats rats: [Rat]) -> [RatsActivityItemProvider] {
var providers: [RatsActivityItemProvider] = []
providers.append(RatsActivityItemProvider(placeholderItem: NSAttributedString(), rats: rats))
providers.append(RatsActivityItemProvider(placeholderItem: RatPrintPageRenderer(), rats: rats))
providers.append(RatsActivityItemProvider(placeholderItem: [:] as [String:Any], rats: rats))
providers.append(RatsActivityItemProvider(placeholderItem: Data(), rats: rats))
return providers
}
override var item: Any {
print("\(activityType!.rawValue as Any) - \(type(of: placeholderItem!))")
switch activityType {
case UIActivity.ActivityType.print:
return RatPrintPageRenderer(rats)
case UIActivity.ActivityType.copyToPasteboard:
var pasteboardDict: [String:Any] = attrString.pasteables()
// (Add custom types to dictionary here)
return pasteboardDict
default:
// "Save To Files" activity is not available in UIActivity.ActivityType so check the raw value instead
if activityType?.rawValue.contains("com.apple.CloudDocsUI.AddToiCloudDrive") ?? false {
//
// HOW TO HAVE ONLY ONE OF THE PROVIDERS RETURN A VALUE HERE???
//
}
}
}
}
When I run this and choose "Save to Files" I get the following output (one line from each of the providers):
com.apple.CloudDocsUI.AddToiCloudDrive - NSConcreteAttributedString
com.apple.CloudDocsUI.AddToiCloudDrive - RecipePrintPageRenderer
com.apple.CloudDocsUI.AddToiCloudDrive - __EmptyDictionarySingleton
com.apple.CloudDocsUI.AddToiCloudDrive - _NSZeroData
...and a file gets created for each of these, if I simply pass back the item for that data type.
Well, I've found that the solution was two-fold...
Direct Answer To Question (but not ideal behaviour):
In each of the switch cases (and the if within the default case), I needed to check that the activityType matches the placeholderItem. If it is not a suitable match, then return the (empty) placeholderItem as-is (except that in the "Save to Files" case, even the empty print page renderer placeholder resulted in a file being written! so instead of returning the placeholder there, return an empty array).
This worked, and resulted in a single file being written to a location of the users choice, which answers the original question. The user even gets the chance to provide a name for the file. But the default name is not good at all - just the data type (eg, "text" or "data", depending on what was being saved to the file).
Solution that Gives More Flexibility:
Create a custom UIActivity that will write the file to a location chosen by the user using a UIDocumentPickerViewController. Eg, The activity can have a title like, "Export to ").
This proved to be a lot more flexible, and let me use a default file name (and extension!) that made a lot more sense, based on the data being passed in. It also has the potential for me to add further improvements to behaviour later (eg, I might be able to use an alert to get the user to choose between a couple of different file formats (to use for different purposes).
This does not replace the "Save to Files" action, so I end up with both of them, and still needed to fix my "Save to Files" action's behaviour as described above.
It leaves me with both an "Export" and a "Save" action, which work similarly, but one is more flexible and intuitive than the other, and I can make them use different file formats by default.
My new code (for the default part of the outer switch) is below...
default:
if activityType?.rawValue == "com.stuff.thing.activity.export" {
if placeholderItem is [Rat] {
return rats
} else {
return placeholderItem!
}
} else if activityType?.rawValue == "com.apple.CloudDocsUI.AddToiCloudDrive" {
if placeholderItem is Data {
return attrString
} else {
// Don't return the placeholder item here! Some (eg print page renderer) can result in a file being written!
return [] as [Any]
}
}
return attrString
}

How can customData can be binded with JavaScript

In the affected application is a responsive table whose ColumnListItems are added via JavaScript code. Now the lines should be highlighted by the highlighting mechanism depending on their state. The first idea was to control the whole thing via a normal controller function. I quickly discarded the idea, since the formatter is intended for such cases. So I created the appropriate Formatter function and referenced it in the JavaScript code. The call seems to work without errors, because the "console.log" is triggered in each case. Also the transfer of fixed values is possible without problems. However, the values I would have to transfer are located within customData of each line...
No matter how I try to form the path I get an "undefined" or "null" output.
I have already tried the following paths:
"/edited"
"/customData/edited"
"mAggregations/customData/0/mProperties/value"
"/mAggregations/items/0/mAggregations/customData/0/mProperties/value"
The code from Controller.js (with consciously differently indicated paths):
var colListItem = new sap.m.ColumnListItem({
highlight: {
parts: [{
path: "/mAggregations/items/0/mAggregations/customData/0/mProperties/value"
}, {
path: "/edited"
}],
formatter: Formatter.setIndication
},
cells: [oItems]
});
// first parameter to pass while runtime to the formatter
colListItem.data("editable", false);
// second paramter for the formatter function
colListItem.data("edited", false);
oTable.addItem(colListItem);
The code from Formatter.js:
setIndication: function (bEditable, bEdited) {
var sReturn;
if (bEditable && bEdited) {
// list item is in edit mode and edited
sReturn = "Error";
} else if (bEditable || bEdited) {
// list item is in edit mode or edited
sReturn = "Success";
} else {
sReturn = "None";
}
return sReturn;
}
The goal would also be for the formatter to automatically use the value of the model in order to avoid its own implementation of a listener, etc.
I hope one of you has a good/new idea that might bring me a solution :)
Many thanks in advance!
You cannot bind against the customData. Because the customData is located in the element, it is like a property.
Thats why you defined it here on colListItem: colListItem.data("key", value)
You only can bind against a model.
So I see three solutions
Store the information in a separate local JSON model whereof you can speficy your binding path to supply the values to your formatter
Do not supply the information via a binding path to the formatter, but read a model/object/array from a global variable in the controller holding the information via this (=controller) in formatter function
Store the information in the customData of each element and access the element reference in the formatter function via this(=ColumnListItem).data().
Passing the context to the formatter similar to this formatter: [Formatter.setIndication, colListItem]
Cons of 1. and 2: you need a key for a respective lookup in the other model or object.
From what I understand I would solve it with solution 3.

AG-Grid with TreeData using Enterprise Row Model

I am trying to implement a grid with tree data using ag-grid. I am using the Enterprise Row Model. The problem is that when hard coding the data and setting it through setRowData the grid displays perfectly. However, when data is loaded through the enterprise row model, the grid does not render as a tree. In fact, the getDataPath callback is not even being called.
Did anyone manage to use the tree data feature with an enterprise data source as this does not seem to be documented?
Thanks
I am assuming that by Enterprise row model, you mean Serverside row model so you expect tree structured data from server. In that case, I have been able to combine following features in Ag-grid : Infinite scrolling + Tree data + server side row model.
I have even implemented custom filtering and it's working as expected.
Data flow:
We have to enable the server side row model on ag-grid using its configuration.
Implement a fake server and proxy data source objects in JavaScript. The object of data source must contain a method named "getRows" that ag-grid can call. Ag-grid will call this method every time user performs actions such as: scroll, filter, sorting, expanding a parent row to see child rows etc.
Implement a method called onGridReady() which will be called by ag-grid every time it's trying to render the grid first time, and then pass the server and dataSource objects to ag-grid's internal API inside onGridReady().
Implementation (using combination of ReactJS and plain JavaScript):
Enable serverSide row model in ag-grid.
<AgGridReact
columnDefs={this.columnDefs}
rowModelType={this.rowModelType}
treeData={true}
isServerSideGroup={this.isServerSideGroup}
getServerSideGroupKey={this.getServerSideGroupKey}
onGridReady={this.onGridReady}
cacheBlockSize={50}
/>
Implement a fake server and proxy data source objects in JavaScript.
To work with server side row model, you need to supply the data in an instance of ServerSideDataSource in JavaScript. Instance of ServerSideDataSource must have a method called getRows() which will be called by ag-grid every time user scrolls down to get next set of data or a row is expanded for retrieving its children records in Tree structure.
The constructor for ServerSideDataSource accepts a proxy data container, typcailly used in ag-grid example: a fakeServer instance. A singleton instance of fakeServer holds the data that was received from the real server and keeps it for following usage:
a) when ag-grid wants to display child records, it calls getRows. Because we supply a custom implementation of this ServerSideDataSource, we can write logic inside getRows to extract data from this fakeServer instance.
b) When ag-grid tries to display next set of data in infinite scrolling or paging, it checks how much data was last retrieved to ask for next block in infinite scrolling (using startRow and endRow variable).
Defining fake server and server side data source:
function createFakeServer(fakeServerData) {
function FakeServer(allData) {
this.data = allData;
}
FakeServer.prototype.getData = function(request) {
function extractRowsFromData(groupKeys, data) {
if (groupKeys.length === 0) {
return data; //child records are returned from here.
}
var key = groupKeys[0];
for (var i = 0; i < data.length; i++) {
if (data[i].employeeId === key) {
return extractRowsFromData(groupKeys.slice(1), data[i].children.slice());
}
}
}
return extractRowsFromData(request.groupKeys, this.data);
};
return new FakeServer(fakeServerData);
}
function createServerSideDatasource(fakeServer) {
function ServerSideDatasource(fakeServer) {
this.fakeServer = fakeServer;
}
ServerSideDatasource.prototype.getRows = function(params) {
console.log("ServerSideDatasource.getRows: params = ", params);
var rows = this.fakeServer.getData(params.request);
setTimeout(function() {
params.successCallback(rows, rows.length);
}, 200);
};
return new ServerSideDatasource(fakeServer);
}
Implement onGridReady()
Once this dataSource is ready, you have to supply this to ag-grid by calling its API method: params.api.setServerSideDataSource(). This API is available inside onGridReady() method that must be passed to Ag-grid as well. This method is mandatorily required if you're using serverSide row model.
onGridReady = params => {
...
var fakeServer = createFakeServer(jsonDataFromServer);
var dataSource = createServerSideDatasource(fakeServer);
params.api.setServerSideDatasource(dataSource);
}
Providing a key property that help ag-grid identify parent-child relationship. You have to supply these parameters to grid. Check the point (1) in Implementation that has HTML syntax and shows how to supply these methods to ag-grid.
var rowModelType = "serverSide";
var isServerSideGroup = function (dataItem) {
return !!dataItem.children;
};
var getServerSideGroupKey = function (dataItem) {
return dataItem.employeeId;
};
Notice that in getServerSideGroup(), we are returning a boolean value which checks whether children property of current row (i.e. dataItem) has any children or not.
I would request you to separately look through documents for server side row model for each feature and that means Tree data (client model) and Tree data (server side model) have two different approaches. We can't setup one model and expect it to work with data of other model.
Documentation for server side row model : https://www.ag-grid.com/javascript-grid-server-side-model/
Please try this and let me know. I had these requirements a month ago, so I contacted them for their help on Trial Support and they have prepared a plunker for this problem statement:
Working example for Tree data from server side with infinite scroll. https://next.plnkr.co/edit/XON5qvh93CpURbOJ?preview
Note:
Since the tree data is being retrieved from server, you can't use getDataPath.
Tree data would be in nested hierarchy per row unlike the client-side tree model. So unique column names are not encapsulated in an array.
Wrong :
var rowData = [
{orgHierarchy: ['Erica'], jobTitle: "CEO", employmentType: "Permanent"},
{orgHierarchy: ['Erica', 'Malcolm'], jobTitle: "VP", employmentType: "Permanent"}
...
]
Right :
[{
"employeeId": 101,
...
"children": [
{
"employeeId": 102,
...
"children": [
{
"employeeId": 103,
...
},
{
"employeeId": 104,
...
}
]},
]}
}]
There was one point when the grid was not being rendered at all in initial phase when I was just setting up the grid with Enterprise features and so it's their recommendation to use px instead of % for height and width of the wrapper DIV element that contains your Ag-grid element.
Edit:
If you prefer to fetch children record in separate API calls to save initial load time then you can make these API calls inside getRows() method. API call will have success and error callbacks. Inside the success callback method, once you receive the children data, you can pass them to ag-grid using:
params.successCallback(childrenData, childrenData.length);
Example: When a parent row is expanded, it sends a unique key of that parent row (which you must have configured already) through params.request.groupKeys. In this example, I am using JavaScript's fetch() to represent API calling. This method accepts ApiUrl, and optional request parameters' object in case of POST/PUT requests.
ServerSideDatasource.prototype.getRows = function(params) {
//get children data based on unique value of parent row from groupKeys
if(params.request.groupKeys.length > 0) {
fetch(API_URL, {...<required parameters>...})
.then(response => response.json(), error => console.log(error))
.then((childrenData) => {
params.successCallback(childrenData, childrenData.length);
});
}
else {
//this blocks means - get the parent data as usual.
params.successCallback(this.fakeServer.data, this.fakeServer.data.length);
}
};
Adding import 'ag-grid-enterprise' followed by initializing the enterprise key resolved the issue of getDataPath not working correctly.
Using example provided by Akshay Raut above, I was inspired to combine server side pagination, and client side grouping. Following his steps, with a slight change. On the getServerSideDatasource function, you can check if the parent node have the children, and rather than calling the server, just return the children directly. That way, you will be able to display the already loaded children as client side. Here is a sample code:
getServerSideDatasource(): IServerSideDatasource {
return {
getRows: (params) => {
if (params.request.groupKeys.length > 0) {
params.success({
rowData: params.parentNode.data.sales,
rowCount: params.parentNode.data.sales.length,
});
} else {
// Your regular server code to get next page
}
Here is a stackblitz:
https://stackblitz.com/edit/ag-grid-angular-hello-world-1gs4jx?file=src%2Fapp%2Fapp.component.ts
Make sure you are using gridOptions.treeData = true An example is here.
Hierarchy of data should be properly set when you implement the gridOptions.getDataPath(data)
Make sure you have implemented Enterperise.getRows Read more
If the above things don't work, share your code here to understand the overall picture better.
Infinite Scrolling or Enterprise/Serverside datasources are not compatible with Tree Data
https://www.ag-grid.com/javascript-grid-row-models/
So you have to either change your code to use Client Side Row Model or use Row Grouping (only available in enterprise)

Zend Framework: is there a way to access the element name from within a custom validator?

I'm writing a custom validator that will validate against multiple other form element values. In my form, I call my custom validator like this:
$textFieldOne = new Zend_Form_Element_Text('textFieldOne');
$textFieldOne->setAllowEmpty(false)
->addValidator('OnlyOneHasValue', false, array(array('textFieldTwo', 'textFieldThree')));
My validator will check that only one of those three fields (textFieldOne, textFieldTwo, textFieldThree) has a value. I want to prevent a future developer from accidentally passing the same field twice.
$textFieldOne->addValidator('OnlyOneHasValue', false, array(array('textFieldOne', 'textFieldTwo', 'textFieldThree')));
So far, my validator works perfectly, except when I pass the same field name as the field that has the valiator set on it.
In my validator, you can see that I am checking that the value (of the element with the validator set on it). I'm also checking the values of the other fields that were passed to the validator.
public function isValid($value, $context = null) {
$this->_setValue($value);
$this->_context = $context;
if ($this->valueIsNotEmpty()) {
if ($this->numberOfFieldsWithAValue() == 0) {
return true;
}
$this->_error(self::MULTIPLE_VALUES);
return false;
}
if ($this->numberOfFieldsWithAValue() == 0) {
$this->_error(self::ALL_EMPTY);
return false;
}
if ($this->numberOfFieldsWithAValue() == 1) {
return true;
}
if ($this->numberOfFieldsWithAValue() > 1) {
$this->_error(self::MULTIPLE_VALUES);
return false;
}
}
private function valueIsNotEmpty() {
return Zend_Validate::is($this->_value, 'NotEmpty');
}
private function numberOfFieldsWithAValue() {
$fieldsWithValue = 0;
foreach ($this->_fieldsToMatch as $fieldName) {
if (isset($this->_context[$fieldName]) && Zend_Validate::is($this->_context[$fieldName], 'NotEmpty')) {
$fieldsWithValue++;
}
}
return $fieldsWithValue;
}
My solution is to either...
A. Let the developer figure out there is a certain way to do it.
B. Ignore $value, forcing you to pass all the elements (which isn't much different than the first option).
or C. (if possible) Find the name of the element that called my validator in the first place and ignore it from the list of $fieldsWithValue.
I don't think there is a way to apply a validator on a form without attaching it to an element, but that would be even better, if it were an option.
How can I solve this problem?
Normaly i'd advise against such things, but, in this case I believe a static member in your class would actually provide a good solution to this problem.
With a static member, you can set it to the value in the first time the isValid is called, and check against it in subsequent calls, thus giving you a mechanism for this.
You may want to set this up to use some array in the configuration options, so that you can namespace and allow multiple instances of the validator to exist happily alongside each other for different sets.
The only problem that you really have to decide how to overcome, is where you wish to display the error, as yes the form itself does not take validators. if you want all the duplicates after the first to display an error, it is not so much of a problem.