Commit 0da8d5b7 authored by Alex Moore's avatar Alex Moore

Fixed bug where app would crash on reaching error; cleaned up scan history...

Fixed bug where app would crash on reaching error; cleaned up scan history parsing by implementing Jake's JSON stuff; rearranged code to increase robustness - app now has basic capability to determine when it has failed with no hope of recovery (aka if PLUC RTI webpage changes)
parent efdeda8d
File deleted
./DS_Store
./WAMI.xcodeproj/xcuserdata
\ No newline at end of file
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
EF0F973F1ACA61C5008D8416 /* BookBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = EF0F973E1ACA61C5008D8416 /* BookBuilder.m */; };
EF0F97411ACA7003008D8416 /* Book.m in Sources */ = {isa = PBXBuildFile; fileRef = EF0F97401ACA7003008D8416 /* Book.m */; };
EFDA4ED31ABFC128002B9CEC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EFDA4ED21ABFC128002B9CEC /* main.m */; };
EFDA4EDE1ABFC128002B9CEC /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EFDA4EDD1ABFC128002B9CEC /* Images.xcassets */; };
EFDA4EE11ABFC128002B9CEC /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = EFDA4EDF1ABFC128002B9CEC /* LaunchScreen.xib */; };
......@@ -51,6 +53,10 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
EF0F973A1ACA604B008D8416 /* Book.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Book.h; sourceTree = "<group>"; };
EF0F973D1ACA61C5008D8416 /* BookBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BookBuilder.h; sourceTree = "<group>"; };
EF0F973E1ACA61C5008D8416 /* BookBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BookBuilder.m; sourceTree = "<group>"; };
EF0F97401ACA7003008D8416 /* Book.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Book.m; sourceTree = "<group>"; };
EFDA4ECD1ABFC128002B9CEC /* WAMI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WAMI.app; sourceTree = BUILT_PRODUCTS_DIR; };
EFDA4ED11ABFC128002B9CEC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EFDA4ED21ABFC128002B9CEC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
......@@ -203,6 +209,8 @@
isa = PBXGroup;
children = (
EFDA4F321ABFC1ED002B9CEC /* AppDelegate.h */,
EF0F973A1ACA604B008D8416 /* Book.h */,
EF0F973D1ACA61C5008D8416 /* BookBuilder.h */,
EFDA4F331ABFC1ED002B9CEC /* Captuvo.h */,
EFDA4F341ABFC1ED002B9CEC /* CaptuvoOptionsController.h */,
EFDA4F351ABFC1ED002B9CEC /* CaptuvoScannerController.h */,
......@@ -222,12 +230,14 @@
isa = PBXGroup;
children = (
EFDA4F3E1ABFC211002B9CEC /* AppDelegate.m */,
EF0F97401ACA7003008D8416 /* Book.m */,
EFDA4F3F1ABFC211002B9CEC /* CaptuvoOptionsController.m */,
EFDA4F401ABFC211002B9CEC /* CaptuvoScannerController.m */,
EFDA4F411ABFC211002B9CEC /* CaptuvoViewController.m */,
EFDA4F421ABFC211002B9CEC /* GlobalWebController.m */,
EFDA4F431ABFC211002B9CEC /* LogInViewController.m */,
EFDA4F441ABFC211002B9CEC /* ScanBookViewController.m */,
EF0F973E1ACA61C5008D8416 /* BookBuilder.m */,
EFDA4F451ABFC211002B9CEC /* SectionViewController.m */,
EFDA4F461ABFC211002B9CEC /* Session.m */,
EFDA4F471ABFC211002B9CEC /* SettingsViewController.m */,
......@@ -365,10 +375,12 @@
EFDA4F4D1ABFC211002B9CEC /* GlobalWebController.m in Sources */,
EFDA4F491ABFC211002B9CEC /* AppDelegate.m in Sources */,
EFDA4F511ABFC211002B9CEC /* Session.m in Sources */,
EF0F973F1ACA61C5008D8416 /* BookBuilder.m in Sources */,
EFDA4F531ABFC211002B9CEC /* WebViewController.m in Sources */,
EFDA4F4B1ABFC211002B9CEC /* CaptuvoScannerController.m in Sources */,
EFDA4F521ABFC211002B9CEC /* SettingsViewController.m in Sources */,
EFDA4F4A1ABFC211002B9CEC /* CaptuvoOptionsController.m in Sources */,
EF0F97411ACA7003008D8416 /* Book.m in Sources */,
EFDA4ED31ABFC128002B9CEC /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -486,6 +498,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS[arch=*]" = TESTING;
INFOPLIST_FILE = WAMI/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
......
No preview for this file type
//
// Book.h
// WAMI
//
// Created by PLUC SeniorDesign on 3/31/15.
// Copyright (c) 2015 BucknellECE_SeniorDesignTeam1. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Book : NSObject <NSCopying>
@property (strong, nonatomic) NSString *barcode;
@property (strong, nonatomic) NSString *callnum;
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *error;
@end
//
// Book.m
// WAMI
//
// Created by PLUC SeniorDesign on 3/31/15.
// Copyright (c) 2015 BucknellECE_SeniorDesignTeam1. All rights reserved.
//
#import "Book.h"
@implementation Book
- (id)copyWithZone:(NSZone *)zone
{
// Copying code here.
id copy = [[[self class] alloc] init];
if (copy) {
[copy setBarcode:[self.barcode copyWithZone:zone]];
[copy setCallnum:[self.callnum copyWithZone:zone]];
[copy setTitle:[self.title copyWithZone:zone]];
[copy setError:[self.error copyWithZone:zone]];
}
return copy;
}
@end
//
// BookBuilder.h
// WAMI
//
// Created by PLUC SeniorDesign on 3/31/15.
// Copyright (c) 2015 BucknellECE_SeniorDesignTeam1. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface BookBuilder : NSObject
+ (NSArray *)booksFromJSON:(NSData *)objectNotation error:(NSError **)error;
@end
//
// BookBuilder.m
// WAMI
//
// Created by PLUC SeniorDesign on 3/31/15.
// Copyright (c) 2015 BucknellECE_SeniorDesignTeam1. All rights reserved.
//
#import "BookBuilder.h"
#import "Book.h"
@implementation BookBuilder
+ (NSArray *)booksFromJSON:(NSData *)objectNotation error:(NSError **)error
{
NSError *localError = nil;
NSDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:objectNotation options:0 error:&localError];
if (localError != nil) {
*error = localError;
return nil;
}
NSMutableArray *books = [[NSMutableArray alloc] init];
NSArray *results = [parsedObject valueForKey:@"books"];
NSLog(@"Count %lu", (unsigned long)results.count);
for (NSDictionary *bookDic in results) {
Book *book = [[Book alloc] init];
for (NSString *key in bookDic) {
if ([book respondsToSelector:NSSelectorFromString(key)]) {
[book setValue:[bookDic valueForKey:key] forKey:key];
}
}
[books addObject:book];
}
return books;
}
@end
......@@ -28,8 +28,9 @@
if (bookProp.innerHTML != "&nbsp;" && bookProp.innerHTML !== "") {
switch(k) {
case 1: // ID Prop
scannedBooks += '{"id":"' + bookProp.innerHTML.trim() + '", ';
case 1: // ID Prop - called barcode for later JSON processing (so as not
//to interfere with "id" keyword
scannedBooks += '{"barcode":"' + bookProp.innerHTML.trim() + '", ';
break;
case 2: // Call Num
scannedBooks += '"callnum":"' + bookProp.innerHTML.trim() + '", ';
......
......@@ -14,5 +14,5 @@
@property (weak, nonatomic, readwrite) UITextField *txtUsername;
@property (weak, nonatomic, readwrite) UITextField *txtPassword;
- (IBAction)btnLogInTouch:(id)sender;
@end
......@@ -9,20 +9,11 @@
#import "LogInViewController.h"
@interface LogInViewController ()
//@property (weak, nonatomic, readwrite) IBOutlet UITextField *txtUsername;
//@property (weak, nonatomic, readwrite) IBOutlet UITextField *txtPassword;
//- (IBAction)btnLogInTouch:(id)sender;
@end
@implementation LogInViewController
//@synthesize txtUsername;
//@synthesize txtPassword;
//static NSString *USERNAME = @"";//@"alex";
//static NSString *PASSWORD = @"";//@"what";
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
......@@ -32,6 +23,31 @@
[self resetRTI];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *url = [[self.webview request] URL].absoluteString;
NSString *base_dest_url;
#ifdef TESTING
base_dest_url = @"http://162.223.19.75";
#else
base_dest_url = @"http://192.168.1.131";
#endif
if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/"]]
|| [url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTILogin.aspx"]]) {
NSLog(@"1: %@", url);
}
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTISetup.aspx?location=1"]]) {
NSLog(@"2: %@", url);
[self performSegueWithIdentifier:@"segueLogIn" sender:nil];
}
//Page handles username/password errors; now handle deeper errors
else {
NSLog(@"3: %@", url);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"FATAL PAGE ERROR" message:@"Page not recognized, cannot proceed. App will no longer work as expected." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
......@@ -59,15 +75,28 @@
}
-(void) resetRTI {
NSLog(@"Reseting RTI");
//Reset global uiwebview
GlobalWebController *globalWeb = [GlobalWebController resetInstance];
//Create new uiwebview
self.webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
//Set global uiwebview = new uiwebview, mark as initialized
globalWeb.web = self.webview;
globalWeb.isInitialized = true;
//Set current view as delegate of uiwebview
[self.webview setDelegate:self];
#ifndef TESTING
NSLog(@"TESTING not defined");
NSURLRequest *rti = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.131/rti/"]];
//Create URL request for RTI webpage
NSURLRequest *rti;
#ifdef TESTING
rti = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://162.223.19.75/rti/"]];
#else
rti = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.131/rti/"]];
#endif
//Eliminate cache and cookies
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:rti];
//Clean the cookie jar
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
......@@ -75,11 +104,11 @@
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
//Load URL in uiwebview
[self.webview loadRequest:rti];
#else
// Test collection page on mac mini desktop
[self.webview loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"file:///Users/plucseniordesign/Desktop/response.html"]]];//RTISetup.html"]]];
#endif
//Add uiwebview as subview to current view
[self.view addSubview:self.webview];
}
......@@ -96,75 +125,28 @@
*/
- (IBAction)btnLogInTouch:(id)sender {
// NSString *path =
// [[NSBundle mainBundle] pathForResource:@"WhatPage" ofType:@"js"];
// NSString *content = [NSString stringWithContentsOfFile:path
// encoding:NSUTF8StringEncoding
// error:nil];
//
// NSString *page =
// [self.webview stringByEvaluatingJavaScriptFromString:content];
// NSLog(@"PAGE NUMBER IS: %@\n", page);
//
// if ([page isEqual:@"0"]) { // Login Page
// NSString *loginPath =
// [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"js"];
// NSString *login = [NSString stringWithContentsOfFile:loginPath
// encoding:NSUTF8StringEncoding
// error:nil];
//
// NSString *success =
// [self.webview stringByEvaluatingJavaScriptFromString:login];
//
// UIAlertView *loginAlert = [[UIAlertView alloc] initWithTitle:@"Logged In!"
// message:success
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
// [loginAlert show];
// }
NSString *login1Path =
[[NSBundle mainBundle] pathForResource:@"Login1" ofType:@"js"];
NSString *login1 = [NSString stringWithContentsOfFile:login1Path
encoding:NSUTF8StringEncoding
error:nil];
NSString *login2Path =
[[NSBundle mainBundle] pathForResource:@"Login2" ofType:@"js"];
NSString *login2 = [NSString stringWithContentsOfFile:login2Path
encoding:NSUTF8StringEncoding
error:nil];
encoding:NSUTF8StringEncoding
error:nil];
NSString *username = @"user.value = \"";
username = [username stringByAppendingString:[self.txtUsername.text stringByAppendingString:@"\";"]];
NSString *password = @"pword.value = \"";
password = [password stringByAppendingString:[self.txtPassword.text stringByAppendingString:@"\";"]];
NSString *login = [login1 stringByAppendingString:[username stringByAppendingString:[password stringByAppendingString:login2]]];
NSString *login2Path =
[[NSBundle mainBundle] pathForResource:@"Login2" ofType:@"js"];
NSString *login2 = [NSString stringWithContentsOfFile:login2Path
encoding:NSUTF8StringEncoding
error:nil];
//NSLog(@"%@", login);
NSString *login = [login1 stringByAppendingString:[username stringByAppendingString:[password stringByAppendingString:login2]]];
NSString *success =
[self.webview stringByEvaluatingJavaScriptFromString:login];
// UIAlertView *loginAlert = [[UIAlertView alloc] initWithTitle:@"Logged In!"
// message:success
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
// [loginAlert show];
//For testing
#ifdef TESTING
if([self.txtUsername.text isEqualToString:@"circ_admin"] && [self.txtPassword.text isEqualToString:@"silver"]) {//check username and password
[self performSegueWithIdentifier:@"segueLogIn" sender:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect login" message:@"Username or password incorrect" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
#else
[self performSegueWithIdentifier:@"segueLogIn" sender:nil];
#endif
}
@end
......@@ -5,8 +5,8 @@
var inventory = document.getElementById("InventoryRadioBtn");
var missing = document.getElementById("IDMissingRadioBtn");
user.value = "circ_admin";
pword.value = "silver";
//user.value = "circ_admin";
//pword.value = "silver";
GetLocation();
var loc = document.getElementById("LocationSelCtl"); // Location select
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
......@@ -17,7 +17,7 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Username" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1dA-Bp-AXg">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Username" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1dA-Bp-AXg">
<rect key="frame" x="16" y="160" width="79" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
......@@ -46,7 +46,6 @@
</state>
<connections>
<action selector="btnLogInTouch:" destination="BYZ-38-t0r" eventType="touchDown" id="lMz-3L-Q1E"/>
<segue destination="Feu-98-wZh" kind="show" identifier="segueLogIn" id="1yM-zj-aAu"/>
</connections>
</button>
<navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TTD-gb-lM9">
......@@ -79,6 +78,7 @@
<connections>
<outlet property="txtPassword" destination="u4E-6x-G9M" id="sbx-w0-Hox"/>
<outlet property="txtUsername" destination="rFc-Xp-Oik" id="Q9Z-xl-cFg"/>
<segue destination="Feu-98-wZh" kind="show" identifier="segueLogIn" id="mO8-qi-2TI"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
......@@ -121,7 +121,7 @@
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Select" id="2p3-0Z-NXG">
<connections>
<segue destination="chc-VY-Gqa" kind="show" identifier="segueInventoryToScan" id="CJj-2P-TD0"/>
<action selector="selectSelectionToScan:" destination="Feu-98-wZh" id="N94-pH-YAM"/>
</connections>
</barButtonItem>
</navigationItem>
......@@ -143,7 +143,9 @@
<barButtonItem key="rightBarButtonItem" title="Select" id="3yH-Ki-T0s"/>
</navigationItem>
<connections>
<outlet property="selectBtn" destination="2p3-0Z-NXG" id="5qA-J1-5aO"/>
<outlet property="tableView" destination="KQi-KS-V1c" id="bSM-0w-K36"/>
<segue destination="chc-VY-Gqa" kind="show" identifier="segueToScanning" id="9t5-KK-V4p"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="j5n-xV-83T" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
......@@ -21,4 +21,6 @@
@property (weak, nonatomic) IBOutlet UIButton *finishBtn;
@property (weak, nonatomic) IBOutlet UIWebView *test_view;
- (IBAction)unwindFromSettings:(UIStoryboardSegue *)sender;
@end
This diff is collapsed.
......@@ -12,5 +12,6 @@
@interface SectionViewController : WebViewController <UITableViewDataSource, UITableViewDelegate>//, UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView ;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *selectBtn;
@end
......@@ -33,21 +33,10 @@
self.tableView.dataSource = self;
[self.tableView reloadData];
//For testing
#ifdef TESTING
[self.webview loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"file:///Users/plucseniordesign/Desktop/RTISetup.html"]]];
#endif
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//NSLog(@"viewDidAppear");
//[self.view addSubview:self.webview];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[super webViewDidFinishLoad:webView];
NSLog(@"got to collections");
//self.webview = [GlobalWebController getInstance].web;
//Set current view as delegate of uiwebview
[self.webview setDelegate:self];
// Get collections available - Testing GetAvailableCollections
NSString *getAvailablePath =
......@@ -60,13 +49,6 @@
NSString *available =
[self.webview stringByEvaluatingJavaScriptFromString:getAvailable];
// UIAlertView *collectionAlert =
// [[UIAlertView alloc] initWithTitle:@"Collections Available"
// message:available
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
// [collectionAlert show];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\"text\":\"([a-zA-Z\\s]*)\"" options:0 error: Nil];
NSArray *rangeList = [regex matchesInString:available options:0 range:NSMakeRange(0, [available length])];
......@@ -79,6 +61,99 @@
[self.sections addObject:section];
}
[self.tableView reloadData];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//NSLog(@"viewDidAppear");
//[self.view addSubview:self.webview];
}
- (IBAction)selectSelectionToScan:(id)sender {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
if (path) {
//need to call AddCollection, then GetSelectedCollections
//AddCollection
NSString *addSelectedPath =
[[NSBundle mainBundle] pathForResource:@"AddCollection"
ofType:@"js"];
NSString *addSelected =
[NSString stringWithContentsOfFile:addSelectedPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview
stringByEvaluatingJavaScriptFromString:@"var selectedAdd = 49;"];
NSString *add =
[self.webview
stringByEvaluatingJavaScriptFromString:addSelected];
if ([add isEqual:nil]) {
NSLog(@"nil failed");
} else {
NSLog(@"NOT NILL UNFAILED");
}
//GetSelectedCollections
NSString *selectedPath =
[[NSBundle mainBundle] pathForResource:@"GetSelectedCollections"
ofType:@"js"];
NSString *selectedFunc =
[NSString stringWithContentsOfFile:selectedPath
encoding:NSUTF8StringEncoding
error:nil];
NSString *selected =
[self.webview stringByEvaluatingJavaScriptFromString:selectedFunc];
//UIAlertView *selectedAlert =
//[[UIAlertView alloc] initWithTitle:@"Collections Selected"
// message:selected
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
//[selectedAlert show];
NSString *saveSetupPath =
[[NSBundle mainBundle] pathForResource:@"SaveSetup" ofType:@"js"];
NSString *saveSetup =
[NSString stringWithContentsOfFile:saveSetupPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview stringByEvaluatingJavaScriptFromString:saveSetup];
}
else {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"No collection selected!"
message:@"You must select a collection to continue."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *url = [[self.webview request] URL].absoluteString;
NSString *base_dest_url;
#ifdef TESTING
base_dest_url = @"http://162.223.19.75";
#else
base_dest_url = @"http://192.168.1.131";
#endif
if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTISetup.aspx?location=1"]]) {
NSLog(@"1: %@", url);
}
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTIScan.aspx?location=1"]]) {
NSLog(@"2: %@", url);
[self performSegueWithIdentifier:@"segueToScanning" sender:nil];
}
else {
NSLog(@"3: %@", url);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"FATAL PAGE ERROR" message:@"Page not recognized, cannot proceed. App will no longer work as expected." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void)didReceiveMemoryWarning {
......@@ -166,66 +241,11 @@
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
//segue to scan
if ([segue.identifier isEqual: @"segueInventoryToScan"]) {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
Session *session = [[Session alloc] init];
session.section = [self.sections objectAtIndex:path.row];
ScanBookViewController *destViewController = [segue destinationViewController];
destViewController.session = session;
//need to call AddCollection, then GetSelectedCollections
//AddCollection
NSString *addSelectedPath =
[[NSBundle mainBundle] pathForResource:@"AddCollection"
ofType:@"js"];
NSString *addSelected =
[NSString stringWithContentsOfFile:addSelectedPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview
stringByEvaluatingJavaScriptFromString:@"var selectedAdd = 49;"];
NSString *add =
[self.webview
stringByEvaluatingJavaScriptFromString:addSelected];
if ([add isEqual:nil]) {
NSLog(@"nil failed");
} else {
NSLog(@"NOT NILL UNFAILED");
}
//GetSelectedCollections
NSString *selectedPath =
[[NSBundle mainBundle] pathForResource:@"GetSelectedCollections"
ofType:@"js"];
NSString *selectedFunc =
[NSString stringWithContentsOfFile:selectedPath
encoding:NSUTF8StringEncoding
error:nil];
NSString *selected =
[self.webview stringByEvaluatingJavaScriptFromString:selectedFunc];
//UIAlertView *selectedAlert =
//[[UIAlertView alloc] initWithTitle:@"Collections Selected"
// message:selected
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
//[selectedAlert show];
NSString *saveSetupPath =
[[NSBundle mainBundle] pathForResource:@"SaveSetup" ofType:@"js"];
NSString *saveSetup =
[NSString stringWithContentsOfFile:saveSetupPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview stringByEvaluatingJavaScriptFromString:saveSetup];
} else { //segue back to log-in
}
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
Session *session = [[Session alloc] init];
session.section = [self.sections objectAtIndex:path.row];
ScanBookViewController *destViewController = [segue destinationViewController];
destViewController.session = session;
}
......
......@@ -42,65 +42,65 @@
// Dispose of any resources that can be recreated.
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Strictly for debugging purposes
//[webView stringByEvaluatingJavaScriptFromString:@"var test1 = 'Hello Pluto'"];
//NSString *newHtml = [webView stringByEvaluatingJavaScriptFromString:@"test1"];
//NSLog(@"%@\n", newHtml);
NSURLRequest *currentRequest = [webView request];
NSURL *currentURL = [currentRequest URL];
NSLog(@"Current URL is %@", currentURL.absoluteString);
NSString *path =
[[NSBundle mainBundle] pathForResource:@"WhatPage" ofType:@"js"];
NSString *content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:nil];
//prevPage = page;
page = [webView stringByEvaluatingJavaScriptFromString:content];
NSLog(@"PAGE NUMBER IS: %@\n", page);
//NSLog(@"PREV PAGE NUMBER IS: %@", prevPage);
if ([page isEqual:@"0"]) { //Login Page
NSLog(@"Login");
}
else if ([page isEqual:@"1"]) { // Setup Page
NSLog(@"Setup");
} else if ([page isEqual:@"2"]) { // Scan Page
NSLog(@"Scan");
} else if ([page isEqual:@"3"]) { // Error/Action Page
NSLog(@"Error");
// Get the error - Testing GetError
NSString *getErrorPath =
[[NSBundle mainBundle] pathForResource:@"GetError" ofType:@"js"];
NSString *getError = [NSString stringWithContentsOfFile:getErrorPath
encoding:NSUTF8StringEncoding
error:nil];