I have a two stories, one quite basic and the other has some conditional branching.
Story 1
User says "Menu", bot fires custom action "show_menu".
Story 2
User says 'Hi'
Fire custom action 'get_activation_state', which sets either schedule_active, or schedule_inactive context attributes.
The story branches.
IF schedule not active then Bot says "Blah..You need to activate", Bot executes 'show_activation'. User says 'Activate' (This is actually, hopefully, via a postback from messenger).Bot executes 'activate_schedule'
IF schedule ACTIVE, bot says "How can I help".
All of this works fine if I stick to the script, but if after the activate schedule function fires (which just inserts a button with 'activate') the user chooses to type 'Menu' then Wit (or my use of Wit) needs to be smart enough to abandon its current story line, and start the menu story. Trouble is, its not.
Any help welcomed!
Related
This is my first take on a state machine and got a bit confused about the possible states that i can define while implementing the subject matter.
P.s. (this question is about how to infer states from a problem and not about how to actually implementing it in code. I know and have used xstate lib).
Scenario is simple, a password field with few validation rules.
The states i came up with are
default ( when the form loads or reset button is pressed)
filled ( should this even be a state ?)
valid ( date is present with all rules satisfied)
invalid (data is there but not meeting the rules )
Error message is displayed based on the current state.
For example, in default state, user didn't enter any data yet, so logical it is invalid state.
But we do not want to show errors to the user right away after opening the form (that will be horrible ux, right ?)
So I added a state specifically for that purpose.
Is this right?
Can it be further simplied or is there a state i am missing?
Secondly, there seems to be arbitrary states
Like
validating
submitting
Should these also be in the mix of states?
They look like states to me though.
Lastly, can we say
submitted is also a state ?
invalid after submitted due to error in API call ( maybe API team added a new rule we didn't know).
Million dollar questions are,
am i even thinking in the right direction to implement validation this way?
is there any state i am missing or overdoing?
You've probably already solved this, but just in case somebody else comes across this question and could use some pointers - I found the trick was to keep in mind that even simple elements have often multiple states in parallel, e.g. a button can be disabled and show a loading spinner at the same time, a menu can be open and fetching data, an avatar can be showing a placeholder and fetching an image at the same time etc.
for your example I'd look at it like this:
Field level
If you think in terms of a password field, it actually has multiple parallel states at the same time:
Interaction
Validity
Visibility
All three states exist at the same time and have multiple child states
Interaction
this should probably mirror the default input events and have matching state events (e.g. onChange -> set to changed):
blurred
focussed
changed
...
Validity
probably just two states, potentially three if you need asynchronous validation (e.g. if you need to check if an email already exists). For a password field you'd just use:
valid
invalid
validating (optional)
Visibility
straight forward:
visible
hidden
Form level
You probably end up with two main states with multiple child states:
form
error
Form
Idle
Editing
Validating
Submitting
Error
That could translate into an alert which you show when e.g. an account already exists or the login details can't be verified:
Inactive
Active
Your form state machine would basically handle the input, validation, submission, and form errors, and just communicate the state to individual field machines (field error messages etc). Alternatively, you could pass the validation rules to the field machines and they can execute the field-level validation on i.e. change events. Things like visibility have nothing to do with the form, so you'd manage the state in the field state machine.
I think you were on the right track, you were just thinking a bit too sequential and not considering parallel states. It's just a matter of taking a step back, looking at the form and thinking about everything that can change in it from a UI point of view.
I am quite new to windows 8 phone and I don't know all the life cycle methods and when what is called.
My problem is the following: I have a page that loads some data from the disk and when the user exits the program ( or suspends ) the data should be saved. As far as I can tell Page doesn't have an OnSuspending method only someOnNavigatingFrom, but those are not called when you just exit the program. So I read that I should use the OnSuspending in my App.xaml.cs, but this class doesn't have this data and also shouldn't have it, maybe only for OnSuspending. But I don't know how to get the data from my page in the OnSuspending method.
The OnSuspending event is quite fragile and you cannot expect it to run and save the state for a long time. But it depends on how long it would take for you to save. It doesn't even get triggered when you hit the home key while closing the app. If you really want an easy way. Just register a background task. While your app is in the background, the state can be saved and when you open the app again things are in place.
There are certain constraints With Background task as well, you cant do heavy lifting etc...here's a link you could use.
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977056.aspx
Implement an observer pattern (i.e. pub/sub) for your view-models to subscribe to in the event that your app is being suspended.
Your app handles the suspended event. As a result, publish a message for your view-models to respond to within your app's method handler for the suspended event.
You can use an EventAggregator or MessageBus (that I wrote).
I have an html form which inserts data into a database. I just built it.. it's very basic, as I'm just doing this to learn. In doing this, I see that I can hit the back browser button and post again.. and again.. and again.. and it keeps writing to the db.
I've seen sites where I try to resubmit info and it tells me I must wait 60 seconds (or whatever). Is this the preferred method to solve this problem? If so, how does one go about implementing it?
Or maybe you would handle it a different way?
When you insert a row, store the submission time in the table, or in the user's session.
Whenever you process the form, compare that time to the current time. If it's within 60 seconds, display an error instead of inserting a row.
There are two methods :
i) Simple client side javascript:
Store the time of last event in a javascript variable,
when the user does the event again , send an alert message about timing.
( This method can be fooled though by users knowing javascript )
ii) Store the time of last event in your database at backend when the form post is done. When the same form post is done again, check for the time, if it is allowed, do the processing, else reply with a message about the timing.
I am trying the post an invoice to SAP using the F-47 transaction and using SHDB to record the transaction and learn how it works. I see there that sometimes BU and ZK BDC OK codes are used. I would like to understand the difference between them, but could not find any official documentation. Please, explain the difference between the two?
I found the meaning of some of the status codes. I post it here, so I can remember:
/00. Enter
/AB Go to overview
=ZK Go to additional information
=ENTE Enter (don't know exactly what is difference between /00)
=PI select cursor location
=STER Go to taxes
=DELZ delete cursor
=GO continue
=BU post (save)
/EEND end processing
=Yes select "yes" from message box
=BP park (save)
=ENTR Enter (don't know exactly what is difference between =ENTE or /00)
=AE save when changing document
=BK change document header (parking or posting parked document)
=P+ next page
=BL delete parked document
A BDC_OKCODE indicates which action is (will) be executed on a screen (things like save, back, exit etc). The BU code is used for a SAVE function (like in MM01 transaction). Sorry but I cannot recall to which function ZK maps to. Obviously their difference lies in the fact that they map to different functions. You can still find out which function each button utilizes by using System->Status->GUI status.
By the way, BTCI transactions are not fully robust- minor changes in GUI flow let your program break. Error handling / analysis is tedious.... DId you have a look to posting methods more preferably? E.g. like BAPI_* function modules? With the help of LSMW you can browse for different input methods and use them later standalone. Or you can use transaction BAPI directly.
Background: We are in the process of writing a registration/payment page, and our philosophy was to code all validation and error checking on the server side first, and then add client side validation as a second step (un-obstructive jQuery).
We wanted to disable double clicks server side, so we wrote some locking, thread-safe code to handle simultaneous posts/race conditions. When we tried to test this, we realized that we could not cause a simultaneous post or race condition to occur.
I thought that (in older browsers anyway) double clicking a submit button worked as follows:
User double clicks submit button.
Browser sends a post on the first click
On the second click, browser cancels/ignores initial post, and initiates a second post (before the first post has returned with a response).
Browser waits for second post to return, ignoring initial post response.
I thought that from the server side it looked like this: Server gets two simultaneous post requests, executes and responds to them both (unaware that no one is listening to the first response).
From our testing (FireFox 3.0, IE 8.0) this is what actually happens:
User double clicks submit button
Browser sends a post for the first click
Browser queues up second click, but waits for the response from the first click.
Response returns from first click (response is ignored?).
Browser sends a post for the second click.
So from a server side: Server receives a single post which it executes and responds to. Then, server receives a second request which it executes and responds to.
My question is, has this always worked this way (and I'm losing my mind)? Or is this a new feature in modern browsers that prevents simultaneous posts to be sent to the server?
It seems that for server side double click prevention, we don't have to worry about simultaneous posts or race conditions. Only need to worry about queued up posts.
A similar situation that you need to handle (that the javascript disable-submit-button solution doesn't cover) is the one where the user clicks Submit, the server processes the request, but while it's processing the user's internet connection goes down (perhaps they're on a train going into a tunnel).
When the train comes out of the tunnel, the user doesn't know whether their transaction succeeded or not - they pressed the button, but nothing changed on the page (or perhaps they got a "Try again" page). The natural thing for them to do is click Submit again (or the "Try again" button).
The best way to handle this situation is to include a unique transaction id in the form (in a hidden field). Generate this id randomly, and when a transaction is successfully processed, store it in the database in a list of completed transactions.
Then when you get a POST, check whether this transaction has already been seen - and if it has, skip straight to the status page. Roughly:
BEGIN TRANSACTION
SELECT *
FROM completedTransactions
WHERE userId = ... AND transactionId = ...
<if we got a result - display results of previous transaction>
<otherwise - process the request as normal>
INSERT INTO completedTransactions (userId, transactionId)
VALUES (....)
END TRANSACTION
This has the advantage that (provided you have a database that properly supports transactions - and since you're processing payments I hope you do!) you don't need to do any sort of threading or locking - things "just work".
(though be careful - some database systems can arbitrarily abort your transactions if there is a concurrency problem - but this (rare) situation is easily dealt with using a retry loop...)
As to testing double clicks from browsers: does it make any difference if you press the "stop" button between the two "submit" clicks?
this may be a stupid response, but why dont you just disable the submit button with javascript on click, so you dont have to worry about multiple clicks. i usually do this on most forms i make and it seems to solve the problem.
you already said you are using javascript so thats not the issue right?
As long as the request is in its connecting or sending stage, clicking on submit during the first submission cancels the request, starting a new one without the server 'knowing'.