How do I force the save routine in ContentTools to save all regions regardless if they changed? - content-tools

I used the save routine from the Getting Started page and it works with my back end coding as long as I edit all regions on the page before saving. However if I don't edit a region it's data is not passed.
The js script on the page above has this:
// Check to see if there are any changes to save
regions = ev.detail().regions;
if (Object.keys(regions).length == 0) {
return;
}
How would I save all the regions even if there aren't changes?
I know it's inefficient but that's how I need to do it right now.

I just figured out that contenttools doesn't even send the region name if it hasn't been edited, so I can check for that in the back end. Problem solved.

Related

Finding gaps/idle times in an array of login/logout data

I have a JSON Object with an array of "employee" objects that indicate a login and logout time for each individual employee. I'm trying to write a function in Swift to show me the times when there are no employees logged in (i.e. the idle or gap time). Additionally this store has a set open/close time so I have the upper and lower bounds of when people could possibly be logged in.
I'm stuck on where to start so any help would be greatly appreciated. I've looked through a number of well known algorithms, but can't seem to find anything. Thank you so much for any help!
The general idea is pretty simple. I'll assume that you can identify a starting place where nobody is logged in, and that your input data is sorted by ascending time.
Build an empty dictionary, keyed by login name. Then start reading the log. When you get a login, add that login name to the dictionary. When you get a logout, remove that login name to the dictionary. Whenever you add a name to an empty dictionary, you've ended an idle period. Whenever removing a name causes the dictionary to be empty, you start an idle period.
Pseudo code is:
names = empty dictionary
while not end of log
if login-type is login
if names contains login-name
// error: already logged in
if names.count == 0
// end of an idle period
idle-end = login-time
names.add(login-name)
else if login-type is logout
if names does not contain login-name
// error: logout without login
names.remove(login-name)
if names.count == 0
// beginning of an idle period
idle-start = login-time
end while
You'll need some additional logic to empty the dictionary at the end of each open period, and allow for early logins (before the official open). But the basic idea above should give you a good start on the project.

Umbraco7 - ContentService.SaveAndPublishWithStatus VS ContentService.SendToPublication

I have an application that uses a combination of ContentService.Saved & ContentService.Saving to extend Umbraco to manage content.
I have two websites in one Umbraco installation I am using those methods to keep content up to date in different parts of the tree.
So far I have got everything working the way I wanted to.
Now I want to add a feature that: depending on which Umbraco User is logged in, will either publish the content or simply send it for approval.
So I have changed some lines of code from:
cs.SaveAndPublishWithStatus(savedNode, 0, false)
To this:
cs.SendToPublication(savedNode);
Now the problem that I am finding is that unlike the SaveAndPublishWithStatus() method, the cs.SendToPublication(); doesn't have the option of passing false so that a save event is not raised. So I get into an infinite loop.
When I attach the debugger and manually stop the infinite loop the first time it calls cs.SendToPublication(savedNode); I get exactly the behavior I want.
Any ideas about how I can get round this problem? Is there a different method that I should be using?
You are correct in saying that it currently isn't possible to set raiseEvents to false when sending an item to publication - that's a problem.
I've added that overload in v. 7.6 (http://issues.umbraco.org/issue/U4-9490).
However considering that you need this now, an interim solution could be that you make sure your code is only run once when triggered by the .Saved / .Saving events.
One way to do this would be to check the last saved date (UpdateDate) in your code. If the content was saved within the last second of the current save operation, you know that this is a save event triggered by the save happening in SendToPublication action. Then you also know that the item has already been sent to publication and that this doesn't need to be done again - thereby preventing the endless loop from happening.

Progress OpenEdge how to prevent someone from updating a record

I need an alternative way to prevent someone from accessing a particular piece of code.
I'll explain the scenario.
There are two programs.
In the first program an end-user creates a proforma invoice. When he/she then views the details on the invoice. The code displays the details with the main table's record in EXCLUSIVE-LOCK. This is to prevent other end-users from changing anything while the first user is busy viewing the details. So even when the proforma invoice is completed and can no longer be changed. The main table's record is still in EXCLUSIVE-LOCK. which is wrong, but it prevents other users from messing with it while the first user is still busy updating it. However, the people who work in this program leave the program in the detail view. They don't go out.
The problem is when the second program is used to dispatch the items on the proforma invoice. It uses the same main table's record. And therefore can't do anything because the first program still has it in EXCLUSIVE-LOCK.
My question is...
How can I prevent users changing data in the first program as if the main table's record was in EXCLUSIVE-LOCK, but without actually having it in exclusive-lock? Over multiple sessions...
This might be better a comment, but I don't have enough reputation points to make comments. Sorry.
Some notes:
Optimistic locking -- if it is viable for your situation -- is almost certainly the best solution.
If you are going to add an isLocked field to the table, you will probably want several other fields:
Date/Time the record was locked -- or else an expiration timestamp
LockHolder -- so you know whether or not you've got it.
The expiration can be automatic (as with a cron sweep), or can be ignored unless someone else wants the record. The program which sets the lock must also be smart enough to check to see if it still holds it. It gets complicated.
There are times when it is not convenient to make schema changes to a table, or there are too many tables that need changes. In those cases, you can add these fields to a separate LockIt table. One table can handle these locks for all your other tables.
Aside:
We also use our LockIt table for another purpose: to make sure that only one copy of a given program can run at a time. (Usually this is for cron jobs or a batch daemon.) The program exclusive-locks a particular record in the LockIt table (but DOES NOT start a transaction!), and it holds that lock as long as the program is running.
Most likely, your transaction scope is wrong. I'll go ahead and assume you are trying to dispatch with the invoicing program still open. Then you can't, because the record is still locked. Chances are your whole program is a transaction, and the record will keep locked for as long as the screen is running. Try and revisit your updates, enclose your real update operations in a DO TRANSACTION block, put some MESSAGE TRANSACTION statements around in different places and see what the results are. This will help you find the points in which Progress is being led to "believe" the record still needs to be locked.
I assume you're not using appserver since this behaviour most likely wouldn't be a problem in that case.
One solution could be to change into a "optimistic locking" approach. This means that you start out with a "NO-LOCK" and once you need to change the record you upgrade the lock to EXCLUSIVE-LOCK. This approach will work but you will need to make sure that the record still exists and isn't changed by some other user.
Depending on how often your invoices actually change this might (or might not) be a solution. If a mishap happens "once in a while" this might be a viable solution. If it happens often (every day or so) you need to do something else.
Basic pseudo code for an optimistic approach:
FIND FIRST record WHERE somethingsomething NO-LOCK.
/* Here goes code for displaying the record */
/* .... */
/* Here's the updates */
IF userWantsToSave THEN DO:
FIND CURRENT record EXCLUSIVE-LOCK NO-ERROR NO-WAIT.
IF AVAILABLE record THEN DO:
IF CURRENT-CHANGED record THEN DO:
MESSAGE "Changed!" VIEW-AS ALERT-BOX ERROR.
/* Your code goes here */
END.
ELSE DO:
/* Your code for updating goes here */
MESSAGE "Success!" VIEW-AS ALERT-BOX INFORMATION.
END.
END.
ELSE IF NOT AVAILABLE record THEN DO:
IF LOCKED record THEN DO:
MESSAGE "Locked!" VIEW-AS ALERT-BOX ERROR.
/* Your code goes here */
END.
ELSE DO:
MESSAGE "Deleted!" VIEW-AS ALERT-BOX ERROR.
/* Your code goes here */
END.
END.
END.
Here's an example from the knowledgebase that goes more into depth with this.

How to know DialogResult with ReportViewer.PrintDialog()

I have encountered this problem a lot of times on the internet, but didn't find a good way to fix this.
What I want is to print a report from the ReportViewer control, and if it has been printed, I need to change some stuff in the database (like the user that printed, what time the reports has been printed).
Now I used the reportViewer.PrintDialog() method (which prints fine) but I can't figure out a way to learn if the user actually printed the document, or cancelled the PrintDialog box.
I also tried the System.Windows.Controls.PrintDialog() which does return a DialogResult, but I couldn't find a way to set the reportViewer's report as the PrintDocument's source.
Has anyone of you found a way to do it?
Thanks in advance, and more info/code can be provided if asked.
Oh
If it's C#
Dialog boxes return a value of type DialogResult
so something like
if (System.Windows.Controls.PrintDialog().ShowDialog() == DialogResult.OK)
{
// Mark item as Prionted by User U
}
In VB.NET, try the following:
If reportViewer.PrintDialog() = Windows.Forms.DialogResult.OK Then
'Put your stuff here
End If

Rails validation fails but object memory remains unchanged?

First time user long time reader. I have thoroughly looked for an explanation for the problem I'm having via the mighty search engine Google, but alas I have failed to produce any significant insight.
I need to be able to ensure that a model form is not reloaded with invalid data. Since the model stored in memory on the server is edited directly with the parameters of the web form first, and THEN checked for validity, without additional code invalid model data will ALWAYS be sent back to the form. This is less than desirable to me. My question is this: how do I ensure this doesn't happen?
What I'm thinking is I need some mechanism for saving the state of the object before it's modified with the parameters sent from the web form, and then after a failed validation restore the object to it's previous, correct and unmodified state of being.
Help!
Thanks,
Les
The object isn't actually modified in the db if validation fails, even though the object is in an invalid state in the form ... the thinking behind this is that the user wants to see the errors they made so they can correct them.
If you don't want that to be the case, then just read back the object with a WhateverObject.find(x) and assign it to the variable that the form is referencing and it will 'restore' the object to its previous unmodified state.
To add to what concept47 said you can also get the value for a particular field using
object.field_was
Have a look at ActiveRecord::Dirty for details (http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html)
Using that you could retrieve the original values for just those fields that had validation errors.

Resources