Is it possible to have HTML content in Gmail.Draft's update method? (body: String) - gmail-api

Is it possible to have HTML content in Gmail.Draft's update method?
In Gmail.Draft's update method, having retrieved a Draft email, like:
var draft = GmaailApp.getDrafts()[0];
Updating works for plain text:
draft.update(recipients, subject, "New text for the draft");
But is it possible to replace the Body
content with HTML content? (the Body parameter is String)
draft.update(recipients, subject, "<b>New text</b> for the draft"); // doesn't work

In order to set HTML body, you have to use the advanced parameter htmlBody:
const options = {
htmlBody: "<b>New text</b> for the draft"
}
draft.update(recipients, subject, "", options)
If you provide that parameter, the body parameter is ignored.
Reference:
GmailDraft.update(recipient, subject, body, options)

Related

Parse content of json in React

I've a response JSON which i would like to parse. Specifically, I am interested in visualizing in an HTML the values contained in the "raw".
Below is an example of the JSON file.
{
"values":{
"first":{
"raw":"first value",
"encoded":"1019570973946118"
},
"second":{
"raw":"second value",
"encoded":"1822871964691"
}
}
}
Using JSON.stringify I can see the entire JSON but, of course that is not my intention.
Thank you
Edit:
I'm sorry, I was very superficial in my initial description. I would like to extract the value contained in raw of this example json file and display it in a react component in HTML. Something like: {JSON.stringify(raw)}
Parsing a JSON string to an actual javascript object is NOT done by JSON.stringify() but by JSON.parse().
So in order to retrieve the raw part you would have to do this:
const response = `{
"values":{
"first":{
"raw":"first value",
"encoded":"1019570973946118"
},
"second":{
"raw":"second value",
"encoded":"1822871964691"
}
}
}`;
const parsedJSON = JSON.parse(response)
for (const key of parsedJSON.values.keys()) {
const raw = parsedJSON.values[key].raw;
console.log(raw)
}
The variable raw could be used as a prop, state, etc. now.

Object Promise is returned when accessing specific object attribute in an array of objects? (Angular - Ionic)

I have an array of objects, I want to be able to mention a specific attribute within a single object within that array. What I have done so far is as follows:
I am storing my array of objects within Ionics storage. I then use an async function to assign the array of objects to an array in my typescript file: This can be seen here;
//The new array
users: User[] = [];
//The async function
async readUsers() {
this.users = await this.service.readUsers();
this.index = this.users.findIndex((x => x.id == this.passed_id));
return this.users[this.index];
}
The async function assigns the array to this.users, after which I then find the object i want and assign its index to this.index, which i then use to identify the desired object in the this.users array. Everything up until here works just fine, i manage to get the desired object within the stored array.
I am then able to read the attributes of the selected object using:
"alert(this.users[this.index].firstName)", instead of the last line in the async function. This works fine as well.
However, now i want to mention a specific object in a form builder control as follows:
firstName: [this.readUsers(), Validators.required],
This does not work, and all that is returned is [Object Promise]. What am i able to do here in order to read a specific attribute (as text) in the form input from the object array mentioned above? Any help is appreciated.
You have to await this.readUsers() for the unwrapped value.
async method() {
...
firstName: [await this.readUsers(), Validators.required],
...
}
Maybe for you, you have to do something like this:
form: any; // using any, but you can change the type to what FormBuilder returns
....
async ngOnInit() {
const users = await this.readusers();
this.form = this.formBuilder.group({
firstName: [users, Validators.required],
});
}

How write data-remote="true" when using createElement in ReactJS?

I'm creating form using createElement() in ReactJSX.
My code looks like this:
var form = document.createElement('form');
form.id = "new_message_form";
form.method = 'post';
form.className = 'chat_input';
I want to use data-remote="true" in this form (it should be something like this:
form.data-remote="true";
Can anybody advise how to do this?
Because there is no standard attribute like data-remote or remote in html forms, it's just custom attribute that is related to rails specificly.
Docs on data-* attributes: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
So, to set that attribute, you need to set this attribute explicitly:
form.setAttribute("data-remote", "true");
JSX
<form id="new_message_form" method="post" className="chat_input" data-remote="true"/>
desugared to JS
React.createElement("form", { id: "new_message_form", method: "post", className: "chat_input", "data-remote": "true" })
You can use JSX online in the Babel REPL to see if it gets compiled to what you need: http://babeljs.io/repl/
I solved my problem with setting attribute directly to form.
Code: form.setAttribute("data-remote", "true");

DotNetNuke MVC Module passing data to different route

I'm trying to pass data to a different route. I use form action and Url.Action but that didn't work. It doesn't even route to another view. It works when I use the anchor tag href with Url.Action, but how do I pass data from one Controller method to the same Controller but a different method.
I have a DNN MVC module example on Github for your reference. https://github.com/DotNetNuclear/DnnRestaurantMenu/blob/master/RestaurantMenu.MVC. You can easily install it by finding the install package under the Releases link.
If you look at the default/index view, there is a link to open the Edit view. If passed an item ID, it will load the data into the edit form, otherwise, with no item ID, it considers it a new (add) item.
So in my View.cshtml, I use DNN's Url.Action helper which forms the button's href. (https://github.com/DotNetNuclear/DnnRestaurantMenu/blob/master/RestaurantMenu.MVC/Views/Menu/Index.cshtml)
<a class="btn btn-default" href="#Url.Action("Edit", "Menu", new {ctl = "Edit", itemId = item.MenuItemId})">#Dnn.LocalizeString("EditItem")</a>
The first parameter is the module control key/action. The second is the controller name. In the 3rd parameter of Url.Action we pass the control type and then any number of additional querystring parameters. In this case, the item Id that is in the view's model.
In my MenuController's Edit() action, I can then take that item ID parameter to lookup the item model from the database and then return the Edit view.
public ActionResult Edit(int itemId = -1)
{
...
if (itemId > 0)
{
item = _menuController.GetItem(itemId, CurrentModuleId);
}
...
}
The only way I have every been able to do this with no headache is to create a routerconfig.cs:
using DotNetNuke.Web.Mvc.Routing;
using RouteParameter = System.Web.Http.RouteParameter;
namespace CodeWompler.CW.GridTest
{
public class RouteConfig : IMvcRouteMapper
{
public void RegisterRoutes(IMapRoute mapRouteManager)
{
mapRouteManager.MapRoute(
moduleFolderName:"CW.GridTest",
routeName: "CW.GridTest",
url: "{controller}/{action}/{id}/{userid}/{itemid}",
defaults: new {
id=RouteParameter.Optional,
userid=RouteParameter.Optional,
itemid=RouteParameter.Optional
},
namespaces: new[] {"CodeWompler.CW.GridTest.Controllers"});
}
}
}
Then, in my index.cshtml, for instance, I can do this:
$.ajax({
url: `/DesktopModules/MVC/CW.GridTest/IMMUser/EditUserById/userid/${myUserId}`,
method: "Post",
headers: {
"ModuleId": moduleId,
"TabId": tabId,
"RequestVerificationToken": rvtoken,
"userId": id //if we were to specify Edit as our url, then we would need this since Edit() takes no parameters and instead, looks in the header for it's data.
}
or
/DesktopModules/MVC/CW.GridTest/IMMUser/EditUserById/${myUserId}
or
/DesktopModules/MVC/CW.GridTest/IMMUser/AssignItemToUser/userid/${myUserId}/itemid/${myItemId}

How to generate a query string in a view from a scope object?

in my view I've got a scope object which contains the params of my query.
What is the easiest way to generate a href attribute using it in a link in my view?
$scope.search_params // => { q: "test", order: "asc", filter: "price" }
// in my view I want to generate a link like this.
...
thanks.
You could use the ng-href directive :
<a ng-href="/search?q={{ search_params.q }}&order={{ search_params.order }}&filter={{ search_params.filter }}">...</a>
If you want to customise your URL (when for example parameters are missing), you should create a custom function in your controller and refer it in the view.
Something like this :
$scope.myHref = function () {
var res = '?';
if (search_param.q) {
res = res + 'q=' + search_param.q;
}
...
}
<a ng-href="/search{{ myHref() }}">...</a>
I think that the first solution is much cleaner, and you should check the given URL after to check if it's null.
More info from the docs.

Resources