Saturday, February 04, 2017

Backbone Views when API Endpoints aren't available...

Let's say you have a view you need to create for a Backbone project. For that view you need a collection of data to display.
BUT, let's also assume that, at the moment, you don't have an API Endpoint or data available from a back end system. But you want to create the GUI for the data that will be forthcoming.

First, determine what your data will look like and then create a standalone JSON file using the same structure that the API Endpoint will eventually return:

view_roles_map.json =
[
     {
            "menuName": "PatientManagement",
            "roles": [
                "National Surgery Admin",
                "Facility Surgery Admin",
                "Surgical Case Admin",
                "Surgery Staff",
                "Surgery Coder"
            ]
        },
        {
            "menuName": "SurgeryMonitoring",
            "roles": [
                "National Surgery Admin",
                "Facility Surgery Admin",
                "Surgical Case Admin",
                "Surgery Case Scheduler",
                "Surgery Case Requestor",
                "Surgery Staff",
                "Surgery Coder"
            ]
        }
]


Next, you're going to need a model for this data:
module.exports = BaseModel.extend({  
     defaults: {  
         "menuName": "",  
         "roles": []  
     }  
 });  
Our simple model has a string as a "menuName" and an array of strings for the "roles" that are assigned to each model in the collection.

Now that we have our model, we'll establish a collection of the data the model will return:
const MenuAccessModel  = require("./model");
module.exports = BaseCollection.extend({
 "url": API.getURL("MenuAccessRoles"),
 "model": MenuAccessModel
});
Notice that we have a function that returns a URL for the data.

Normally this URL is to a RESTful API Endpoint, but in this case the URL is only the URL to the local JSON file we created:
/data_files/view_roles_map.json
That's it we're done.

Now we make use of that collection just as we would any OTHER backbone collection.
const ViewAccessCollection = require("./entities/administration/view_access_config/collection");
 loadViewAccess() {
  const access = new ViewAccessCollection();
  return access.fetch()
   .then(() => Radio.request("store", "set", "viewAccess", access));
 },

Now when an API Endpoint or the data becomes available through an API Endpoint all you have to do is change the URL that your collection/model calls to fetch the data!

Saturday, December 31, 2016

Notes on coding style

My thoughts on using TABS for indentation:

This was taken directly from StackExchange and written by @FishToaster.

Now I make no claim on the belief that this is the "One True" indentation method as that has caused flame wars since coding was invented. But this is MY preference (and @FishToaster's reasoning makes sense and agrees with my beliefs, so...)


Tabs:

Now, of course, consistency matters more than either one, and a good IDE makes the differences negligible. That said, the point of this thread is to be a holy war, so:

I prefer tabs:

  • They're a character specifically meant for indentation
  • They allow developers with different preferences in indentation size to change how it's the code looks without changing the code (separation of data and presentation for the proverbial win!)
  • It's impossible to half-indent something with tabs. So when you copy code from some website that used 3 spaces into your 4-space indented file, you don't have to deal with misalignment.

My thoughts on single vs double quotes:

Now here is another case where flame wars exist. 

My preference is using double quotes. 


For one the JSON spec requires double quoted strings for names and values, and since I run a lot of JSON through JSONLint it's easier to be consistent when I'm writing regular code if I always have to remember to use double quotes. 

About the ONLY time I don't use double quotes is if I'm using backticks (`) in JavaScript where I can actually include variables within a string and have the interpreter convert inline.

For Example:

var n = "Mike";
var buf = "Hello " + n + ". How are you today?";
can be converted to:
var n = "Mike";
var buf = `Hello ${n}. How are you today?`;
I find it's a lot easier to build strings with variables with backticks than with a bunch of additions or such.

Monday, November 17, 2014

Using WebLogic Server to Simply Store Static Content

A couple of weeks ago I saw a forum thread which I found very interesting. A guy was asking if it's possible or not to use WebLogic as a Web Server, in a similar way than when an index.html file is placed on the 'www' directory of Apache. So I answered him.
Actually you can use WebLogic as a web server, but unlike Apache where you place a html file to the www directory and you can see it immediately, in WebLogic you have to deploy it to a domain. 
  1. The html files (or any other static content like pdf files) must be in a directory of your choice (i.e. C:\testhtml). 
  2. On that directory create a WEB-INF directory (from the example of step 1 it would be C:\testhtml\WEB-INF). 
  3. In the WEB-INF directory create a file called web.xml with the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"><web-app></web-app>
  4. Login to the WebLogic Console to deploy the application (i.e. http://[your_server]:7001/console ) 
  5. Click on Deployments. 
  6. Click Install and set the path to the directory of step 3 (if the directory only contains the html file and the WEB-INF subdirectory you will see no files to select, but the Next button will be enabled anyway). 
  7. Leave default "Install this deployment as an application" and click Next. 
  8. Select the servers you wish to deploy this. 
  9. Accept the defaults and click Finish. 
  10. Activate Changes if the message appears. 
  11. You should now be able to see the application started in the deployments screen. 
  12. You can now access your static content on the WebLogic Server port via the following URL: http://[your_server]:7001/testhtml/[your_static_file]

Wednesday, April 23, 2008

TCF 2008

I have had the honour of speaking at TCF for over 20 years now. To be quite honest, I'm not sure just WHEN I started speaking here, but it has always been a very enjoyable experience (even when I used to be part of Keith and Mark Sproul's Volunteer crew and it was pouring rain the entire weekend).

Currently, I am working for Sensor Technologies located out of Red Bank, NJ as an analyst specializing in IBM/Lotus Notes/Domino Technology.

I've been a lecturer on computer topics for over 20 years and been involved in high-end web development since the early 1990's. I've spoken on a wide range of topics including computer viruses, memory management, Lotus Notes/Domino development, advanced web architecture and application development. This year, as in the last several years, my presentations cover some of the new Web Technologies out there, primarily Web 2.0, Ajax and using open source libraries for web development.
________________________________________
RESTful Web Services
Mike Barlow
Saturday 26 April 2008 - BSC 202E, 10:15 am to 11:10 am

Abstract :
Web Services and SOA seem to be all the rage these days, and if you've looked into them most of the articles and books talk about WSDL files and SOAP and fairly complex architectures. But that's NOT the only way of doing Web Services. There's also "REST" based Web Services. REST (which stands for "Representational State Transfer") is "sort of" the new kid on the block when it comes to Web Services, but REST is an easier, faster, and more efficient method of doing Web Services. As a matter of fact, Amazon.Com which provides a REST interface as well as SOAP interface to their Web Service reports that they handle 85% MORE hits via REST than SOAP and REST is 6 times faster! So, come and get the scoop on just what REST is and how you too can have a RESTful Web Service.

________________________________________
Advanced Web Site Development Using Open Source Libraries
Mike Barlow
Saturday 26 April 2008 - Room SB, 11:20 am to 1:20 pm

Abstract :
Ok, well to those of you who saw my presentation on this topic last year, this is a NEW and improved version. Last year I was demonstrating the use of the Mootools library. Well while Mootools has improved vastly and is an even better library than it was last year, I've also investigated some other libraries and one of the newest, slickest, easist librarys to use is ExtJS. So, this time around I'll show you how to make your web site do even fancier things than last year. Simple but snazzy looking "panels" with built in drag-and-drop capability and even a page that looks like a portal (but "technically" isn't). Tab panels which load their content via Ajax and much more. So if you want to keep up on some of the latest Javascript library usage out there, come check this out and go home with some neat new tools in your virtual pocket.

Contact Info:

Web Page:


Tuesday, January 29, 2008

Lotusphere 2008

Well, my friend Erik and I (along w/ about 10,000 other of our closest TAOSRI friends) have survived yet another Lotusphere. Our presentation went quite well (we had a room which holds probably 800 seats and was at least 3/4 full) and is still available at the Lotusphere 2008 conference site. If you were a registered attendee of the conference your username/password is printed on your ID badge, if not the presentation will be available on my web site (http://www.mwbarlow.com) within a day or so as a downloadable PDF file.

Monday, May 21, 2007

Creating a long numeric list with Notes @Formula

Well, I used to be able to write @formula functions like this in my sleep.
But once Lotusscript came out I stopped writing "complex" @formulas like this so forgot how to do it. Then one day when I needed a list like this it took me over an hour searching the old Notes 4/5 forums to find it. So I thought I'd put it here in case I ever need it again.

To create a long list of numbers (say sequential from 0-99) use this formula:

digitList := 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9;
LongList := @TextToNumber(@Text(digitList) *+ @Text(digitList));

If you only need say from 0-48 then do:
@Subset(LongList; 48)

If you want 48 but starting at 1 rather than 0 then:
@Subset(@Subset(LongList; 49); -48);