Couldn't compile yew - rust-cargo

I am using build a sample app from yew docs. I don't know why this app throw this error.
this is yew version in Cargo.toml
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
this is code in main.rs
use yew::prelude::*;
#[function_component]
fn App() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
move |_| {
let value = *counter + 1;
counter.set(value);
}
};
html! {
<div>
<button {onclick}>{ "+1" }</button>
<p>{ *counter }</p>
</div>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
this is index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Yew App</title>
</head>

The code in your screenshot doesn't quite match the example you posted here (there's no UseStateHandle, etc) but assuming that's not an issue I took a quick look at
~/.cargo/registry/src/github.com-1ecc6299db9ec823/yew-0.20.0/src/lib.rs on my system and
https://github.com/yewstack/yew/blob/master/packages/yew/src/lib.rs on github
Neither of those has a pub(crate) fn start_app() -> { at line 348. They only have 346 lines.
I suspect something's wrong with your cargo registry.
You should take a closer look at the files on your system to confirm this.
I don't know if there's a way to correct this but if I were to encounter this condition I would
rename my ~/.cargo/registry to something like ~/.cargo/registry.bak
and then try again.
If that fixed the problem I'd remove the ~/.cargo/registry.bak. If not I'd put it back.

Related

Alert when code is running background in google sheet

Working with Google App script and Javascript, I managed to retrieve xls Gmail attachments, convert it to google sheets, send an warning email to some recipients, insert an event with the Google Drive folder link when a new attachment is added to it, and at the end I managed with a standalone script to import some of the data coming from such xls file converted to a main Google Sheet where one operator is working h24 ( updating some data to be forwarded later on and during the service itself).
The standalone script run every 30 minutes to check incoming mail ( the schedule for the next day or days), and when it find it, it execute the code.
The lock service is not available on standalone scripts up to now, so I cannot lock the document, so I wish to display a message to the user that the script is about to run and not edit anything, since other scripts bounded to the Spreadsheet are using the Lock service, and so the result could be quite disappointing. I searched info regarding this "alert", but I cannot find a clue about it.
Could you address me somewhere?
I could add a menu function instead of a standalone script, and the operator could select "Import data" and that's it, but I wish to automate the operation in background.
You could use the HTML Service. I don't know much about it myself but I think the following may do what you need:
At the top of you .gs file:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var htmlApp = HtmlService.createTemplateFromFile("html");
var status = "Loading....."
htmlApp.data = status;
ss.show(htmlApp.evaluate()
.setWidth(300)
.setHeight(200));
At the end (just before the last brace):
var status = "Finished!"
htmlApp.data = status;
ss.show(htmlApp.evaluate()
.setWidth(300)
.setHeight(200));
In a new HTML script file named 'html':
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h2>Updating..</h2>
<p id="status">(innerHTML).</p>
<div id="imageico"></div>
<script>
var imageContainer = document.getElementById("imageico");
if (<?= data ?> != "Finished!"){
document.getElementById("status").innerHTML = "Running script, please wait..";
} else {
document.getElementById("status").innerHTML = "Finished! You can now close the window.";
closeBtn();
}
function closeBtn(){
var button = document.createElement("INPUT");
button.setAttribute("type", "button");
button.setAttribute("value", "Close");
button.setAttribute("onclick", "closeWindow();");
imageContainer.appendChild(button);
}
function closeWindow(){
google.script.host.close();
}
</script>
</body>
</html>
EDITED Based on comments
In your .gs file:
function test() {
htmlApp("","");
/*
*
* Put your code in here....
*
*/
Utilities.sleep(3000); // change this value to show the "Running script, please wait.." HTML window for longer time.
htmlApp("Finished!","");
Utilities.sleep(3000); // change this value to show the "Finished! This window will close automatically. HTML window for longer time.
htmlApp("","close"); // Automatically closes the HTML window.
}
function htmlApp (status,close) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var htmlApp = HtmlService.createTemplateFromFile("html");
htmlApp.data = status;
htmlApp.close = close;
ss.show(htmlApp.evaluate()
.setWidth(300)
.setHeight(200));
}
In the HTML script file named 'html':
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h2>Updating..</h2>
<p id="status">(innerHTML).</p>
<div id="imageico"></div>
<script>
var imageContainer = document.getElementById("imageico");
if (<?= data ?> != "Finished!"){
document.getElementById("status").innerHTML = "Running script, please wait..";
} else {
document.getElementById("status").innerHTML = "Finished! This window will close automatically.";
}
if (<?= close ?> == "close"){
google.script.host.close();
}
</script>
</body>
</html>
Have a look at this Sample Spreadsheet.
I don't see any methods or sample scripts regarding your concern. But this documentation about alert might help. It will open a dialog box in the user's editor with the given message and an "OK" button. However, this method suspends the server-side script while the dialog is open and the script will resume after the user dismisses the dialog.
You may also execute alert dialogs before running your script.
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Custom Menu')
.addItem('Show alert', 'showAlert')
.addToUi();
}
function showAlert() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.alert(
'Please confirm',
'Are you sure you want to continue?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (result == ui.Button.YES) {
// User clicked "Yes".
ui.alert('Confirmation received.');
} else {
// User clicked "No" or X in the title bar.
ui.alert('Permission denied.');
}
}

What does this websocket url "ws://{{$}}/ws" mean?

I work with websocket in go. And I got a websocket url format from a trivial example that I google like this:
ws://{{$}}/ws
Relatively complete code below:
home.html:
<html>
<head>
<title>Chat Example</title>
<script type="text/javascript">
$(function() {
......
if (window["WebSocket"]) {
conn = new WebSocket("ws://{{$}}/ws");
conn.onclose = function(evt) {
appendLog($("<div><b>Connection closed.</b></div>"))
}
conn.onmessage = function(evt) {
appendLog($("<div/>").text(evt.data))
}
} else {
appendLog($("<div><b>Your browser does not support WebSockets.</b></div>"))
}
......
});
</script>
</head>
</html>
And wsServer.go:
package main
import (
"flag"
"log"
"net/http"
"text/template"
)
var addr = flag.String("addr", ":8080", "http service address")
var homeTempl = template.Must(template.ParseFiles("home.html"))
func serveHome(w http.ResponseWriter, r *http.Request) {
......
w.Header().Set("Content-Type", "text/html; charset=utf-8")
homeTempl.Execute(w, r.Host)
}
func main() {
http.HandleFunc("/", serveHome)
http.HandleFunc("/ws", serveWs)
err := http.ListenAndServe(:8080, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
I thought it would be a regular expression while actually I can't explain it.
I test it on my own PC browser, and connect success with:
http://localhost:8080
but
http://ip:8080 (which ip is my computer's also the litsening server's ip)
not.
And why?
Of course it works when I change "ws://{{$}}/ws" to a certain url. But I want to know why?And what can this expression matching for?
The complete example code is large, I think above is enough to the question. If I miss something you can find out complete example in this page : https://github.com/garyburd/go-websocket/tree/master/examples/chat
I'm guessing you are using the template package of Go. The template package supports {{ placeholders }} that are annotated by those curly brackets. Those curly brackets might contain statements like range, if etc, and variable names. The variable name $ is a special name that points to the root element that was passed to the template.Execute method.
Please add the code of your wsServe method so that we can see what value your are passing to your template. I will extend my answer afterwards.

What would unhook my View and Controller from each other in Chrome and IE but not in Firefox?

I have previously successfully tested this MVC functionality in my app in Chrome but have recenlty also tested in IE (10) and Firefox.
When I mash the submit button on a page which sends model values to its controller for running a query and generating a report, it now works only in Firefox (each of the three browser indeed have their own peculiar characteristics -- where they shine or "dull" in relation to their cohorts (gleaming in purple and gold) -- but Chrome and Firefox seem to have lost the connection between the submit button's click handler and the corresponding Controller's method.
The app seems to simply hang after mashing the submit button in Chrome and IE; the breakpoints I have -- the first of which is at the very beginning of the corresponding [HttpPost] ActionResult in the Controller class -- are not reached. In fact, the app seems to freeze after mashing the button -- right-clicking the submit button after that does not give me an "inspect that element" in the context menu.
[HttpPost]
public ActionResult ReceiptCriteria(SalesReceiptCriteriaModel model)
{
if (ModelState.IsValid) // <-- there is a breakpoint here; only Firefox reaches it
{
. . .
In Firefox, it runs, and the breakpoints are hit.
What could possibly cause Chrome and IE to fail in this way, wheras Firefox soldiers on?
UPDATE
In response to Moby's request, here is the jQuery for the View in question:
The HTML in the View is pretty generic; the jQuery is:
$("#submit_button").click(function() {
// http://stackoverflow.com/questions/18192288/how-can-i-compare-date-time-values-using-the-jqueryui-datepicker-and-html5-time
var begD = $.datepicker.parseDate('mm/dd/yy', $('#BeginDate').val());
var endD = $.datepicker.parseDate('mm/dd/yy', $('#EndDate').val());
if (begD > endD) {
alert('Begin date must be before End date');
$('#BeginDate').focus();
return false;
}
else if (begD.toString() == endD.toString()) {
var dteString = begD.getFullYear() + "/" + (begD.getMonth() + 1) + "/" + begD.getDate();
var begT = new Date(dteString + " " + $('#BeginTime').val());
var endT = new Date(dteString + " " + $('#EndTime').val());
if (begT > endT) {
alert('Begin date must be before End date');
$('#BeginTime').focus();
return false;
}
}
$("#NumberOfResults").css("visibility", "visible");
$("#NumberOfResults").html("Please wait...");
EnableButton("submit_button", false);
// If all are selected, don't enumerate them; just set it at "All" (change of case, from 'all' to 'All', shows that the logic did execute)
var deptsList = $('#depts').checkedBoxes();
if (deptsList.length < deptsArray.length) {
$('#deptHeader span').html(deptsList.join(", "));
}
else if (deptsList.length == deptsArray.length) {
$('#deptHeader span').html("All");
}
// " "
var sitesList = $('#sites').checkedBoxes();
$('#sitesHeader span').html(sitesList.join(", "));
if (sitesList.length < sitesArray.length) {
$('#sitesHeader span').html(sitesList.join(", "));
}
else if (sitesList.length == sitesArray.length) {
$('#sitesHeader span').html("All");
}
$('#hiddenDepts').val(deptsList);
$('#hiddenSites').val(sitesList);
var UPCs = $('#UPC').val();
if (UPCs == "All") {
$('#UPC').val("1"); // take everything (1 and greater)
}
var resultsText = jQuery.trim($("#spanNumberOfResults").text());
if (resultsText != "") {
$("#NumberOfResults").css("visibility", "visible");
if (resultsText == "0") {
$("#NumberOfResults").css("color", "red");
} else {
var href = '/#ConfigurationManager.AppSettings["ThisApp"]/TLDCriteria/LoadReport';
var report_parms = {
GUID: "#Model.GUID",
SerialNumber: "#Model.SerialNumber",
ReportName: "#Model.ReportName"
};
window.open(href, "report_window", "resizable=1, width=850, left=" + (screen.width / 2 - 425));
}
}
}); // end of submit button click
function EnableButton(id, enable) {
if (enable) {
$("#" + id).removeAttr("disabled")
.removeClass("bottomButtonDisabled")
.removeClass("bottomButtonEnabled")
.addClass("bottomButtonEnabled");
} else {
$("#" + id).attr("disabled", "true")
.removeClass("bottomButtonDisabled")
.removeClass("bottomButtonEnabled")
.addClass("bottomButtonDisabled");
}
}
UPDATE 2
Something else which may or may not shed some light on this problem is my .js and .css references:
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" type="text/javascript" defer > </script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript" defer> </script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript" defer> </script>
<script src="#Url.Content("~/Scripts/jquery-migrate-1.2.0.min.js")" type="text/javascript"> </script>
<script src="#Url.Content("~/Scripts/anytime.compressed.js")" type="text/javascript"> </script>
<script src="#Url.Content("~/Scripts/dynamicCheckboxes.js")" type="text/javascript" > </script>
. . .
<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/dynamicCheckboxes.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/anytime.compressed.css")" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="/Scripts/html5shiv.js"> </script>
<![endif]-->
UPDATE 3
The Network tab in the Chrome Developer Tools looks like the middle of Wyoming (a whole lot of nothing), with a msg about the bottom informing me "No requests captured. Reload the page to see detailed information on the network activity."
When I dutifully mashed F5, it showed all the .js and .css files accessed, and finally (at the top), the page I'm gawking at. Mashing the "View Report" causes no more activity in the tab, though. I do see the console.log() msg I placed at the end of the submit button click handler, though, to wit: "made it to the end of submit button click"
There is one err msg in the console, too, but this:
Failed to load resource: the server responded with a status of 400 (Bad Request) http://localhost/%3C%=%20System.Configuration.ConfigurationManager.AppSettings[%22ThisApp%22]%20%%3E/Content/Images/SSCSsprite.png
Would simply fail to load the resource, not wreak other mayhem, right?
UPDATE 4
Based on Simon Halsey's hint, I found that, on stepping though the jQuery in Chrome, it fails this test:
if (resultsText != "") {
...obviously it's not in Firefox, and I assume that it also fails in IE (I'll czech to be sure in both cases, and update this).
Later: It's "" in Firefox, too...and the first time through, it also failed-wouldn't continue on. Second time through, it got through, though...???
There is two options:
There is no request due to javascript error
Your request signature doesnt math controller method
A.
Browsers have different behaivior with some javascript functions. Thats one of the reasons why jQuery is so popular.
The most efficient way to find it is to debug javascript line by line in each browser.
Likely it is the reason.
B.
Also your javascript is quite exotic for me. I guess you are catching sumbit button click and modifying inputs values on a fly.
I would recommend to use $.post or $.ajax and preventDefault instead.
It would make your javascript more clear and simple.
C.
To analyze what requests are sent from your browser I would recommend to use fiddler.
http://fiddler2.com/

qrcode-0.1 with Grails 2.0.1

Look this is my problem: I have updated to Grails 2.0.1 and now I have to make a QR Code. I have installed the qrcode plugin 0.1 but it is not working. I'm usign the tag:
<qrcode:image text="${createPromoInstance.id}" />
but it seems it doesn't do anything. I debugged with google chrome and I realized that in the "Elements" tab, the tag is being changed for <call></call>
I was asking yesterday about this, and someone said me that the plugin has some bugs that doesn't work with Grails 2.0.1, and he gave me some advices about what can I do.
For example, I editted the QRController like this:
class QrcodeController{
QRCodeRenderer qrcodeRenderer = new QRCodeRenderer()
def index = {
qrcodeRenderer.renderPng(response, request.getHeader("REFERER"), 300i)
} //It doesn't have any change
def url = {
String uri = params.u
String size = getSize(params)
qrcodeRenderer.renderPng(response, uri, size.toInteger().intValue())
} //it doesn't have any change
protected String getSize(Map params){
String size = params.s
if(!size || size.matches(/\D\)) {size = "128"}
return size
} //I have added the "protected word"
def text = {
String content = params.t //it used to be params.text
String size = getSize(params)
qrcodeRenderer.renderPng(response, content, size.toInteger().intValue())
}
}
and he said if I make those changes it will work, but no, it doesn't! I'm trying to render the code in an empty gsp just to try it out like so:
<%page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title><title>
<head>
<body>
<div>
<qrcode:image text="${createPromoInstance.id} />
</div>
</body>
</html>
As I understand it should work, but it doesn't. Does anyone know what am I doing wrong? I have to do something else to get the rendered QR Code?
Thanks for the help!
Jonatan!
I found the answer... I will just leave it here if anyone need it.
to get this working you need to do some changes as I wrote before.
protected String getSize(Map params{ //it used to be String getSize(Map params)
String size = params.s
if (!size || size.matches(\/D/) {size = "128"}
return size
}
and
def text = {
String content = params.t //it used to be params.text
String size = getSize(params)
qrcodeRenderer.renderPng(response, content, size.toInteger().intValue())
}
but this is not everything, you have to change something else in the BuildConfig like so:
//find the plugin call
plugins{
//this is how my plugins call looks like, here you might see the calls of the plugins you have installed
runtime: ":hibernate:$grailsVersion"
runtime: ":jquery:1.7.1"
runtime: ":resources:1.1.6"
//and you gotta add this
compile: ":qrcode:0.1"
/*.
.
.*/
build: ":tomcat:$grailsVersion"
}
Then you must go to the plugin taglib "QRCodeTagLib" and replace this:
def image = {attrs->
def size = attrs.height?:attrs.width
String text = attrs.text
String src = createLink(controller:'qrcode',action:'text',params:[t:text,s:size])
//it used to be like this
/*def mkp = new groovy.xml.MarkupBuilder(out)
mkp{
img(alt:url, src:src)
}
*/
//and now it looks like this
out <<"<img alt=\"${text}\" src=\"${src}\"/>"
}
and that's it, your QR Code will be rendered!
Hope it will be useful for anyone!
Jonatan!!
PD: The credit is not mine for this code, somebody helped me on the grails facebook page! Lots of thanks for Ingo. :)
ah! Other thing... He added something in the bootstrap but it didn't work for me, in the bootstrap he put:
QRCode m = new QRCode()
m.save()
try it and let me know if that works for you! :)

Trouble using Titanium's webview to fire an API event

I'm trying to fire an event from an external HTML page opened inside of Titanium's webview.
app.js file...
var group, now, tab, view, window;
now = new Date();
view = Titanium.UI.createWebView({url: 'http://MYWEBSITE.com/index.htm?time=' + now.getTime()});
window = Titanium.UI.createWindow({tabBarHidden: true, navBarHidden: true});
window.add(view);
Titanium.App.addEventListener('browse', function(e) {
Ti.API.info("I received " + e.something + " from the webview.");
});
group = Titanium.UI.createTabGroup();
tab = Titanium.UI.createTab({title: 'window', window: window});
group.addTab(tab);
group.open(tab);
js excerpt from web page...
$("#testButton").mousedown(function() {
alert ("I got clicked.");
Ti.App.fireEvent('browse', {something:'stuff'});
});
(I include the time in the URL to ensure the page is always fresh.)
Adding the event listener as shown above, or using view.addEventListener, compiles but ultimately doesn't work.
Using Titanium.UI.WebView.addEventListener produces an error message that the object doesn't exist.
Do I need to open the URL/webview in a different manner?
Also, since Titanium.App.fireEvent is not a recognized function, except to Titanium, how does one prevent a JavaScript error?
Thanks.
// from web page
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id='testButton'>TEST BUTTON</div>
</body>
<script>
var _button = document.getElementById ("testButton");
_button.onmousedown = function () {
alert (this.id);
Ti.App.fireEvent('fromwebview', {name:this.id});
return false;
};
</script>
</html>
from apps.js
Ti.App.addEventListener('fromwebview', function(data)
{
Titanium.API.info("--> " + data.name);
});
Just to warn you all - I don't think this works with remote pages anymore for security reasons. Spent ages trying fruitlessly!
You can make this work on your remote html page by including the Titanium Injection code. For sdk 1.8.3 it's the following. Now your remote html page can talk to the device.
var Ti = {_event_listeners:[],createEventListener:function(listener ){ var newListener={ listener:listener ,systemId:-1 ,index:this._event_listeners.length };this._event_listeners.push(newListener);return newListener;},getEventListenerByKey:function(key,arg){for(var i=0;i<this._event_listeners.length;i++){if(this._event_listeners[i][key]==arg){return this._event_listeners[i];}} return null;},API:TiAPI,App:{addEventListener:function(eventName,listener) {var newListener=Ti.createEventListener(listener);newListener.systemId=TiApp.addEventListener(eventName,newListener.index);return newListener.systemId;},removeEventListener:function(eventName,listener) {if(typeof listener=='number'){TiApp.removeEventListener(eventName,listener);var l=Ti.getEventListenerByKey('systemId',listener);if(l!==null){Ti._event_listeners.splice(l.index,1);}}else{l=Ti.getEventListenerByKey('listener',listener);if(l!==null){TiApp.removeEventListener(eventName,l.systemId);Ti._event_listeners.splice(l.index,1);}}},fireEvent:function(eventName,data) {TiApp.fireEvent(eventName,JSON.stringify(data));}},executeListener:function(id,data) {var listener=this.getEventListenerByKey('index',id);if(listener!==null){listener.listener.call(listener.listener,data);}}};var Titanium=Ti;

Resources