From 9bf11d1e24103ac4532dec667829cf752ac7bdda Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Thu, 1 Nov 2012 12:17:32 +0000
Subject: [PATCH] Use UIWebView to show images instead of UIImageView.

SVN: 27452
---
 .../BisKit/Classes/CISDOBIpadServiceManager.h |  1 +
 .../BisKit/Classes/CISDOBIpadServiceManager.m |  5 ++++
 .../openBIS/CISDOBDetailViewController.h      |  2 +-
 .../openBIS/CISDOBDetailViewController.m      | 10 +++++--
 .../openBIS/CISDOBMasterViewController.h      |  1 +
 .../openBIS/openBIS/CISDOBOpenBisModel.h      |  3 ++
 .../openBIS/openBIS/CISDOBOpenBisModel.m      | 30 +++++++++++--------
 .../en.lproj/MainStoryboard_iPad.storyboard   | 25 +++++++++-------
 8 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.h b/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.h
index 00ab1fa6f7c..6cac92e2859 100644
--- a/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.h
+++ b/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.h
@@ -37,6 +37,7 @@
 @property (readonly, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator;
 @property (readonly, strong) NSEntityDescription *ipadEntityDescription;
 @property (readonly, strong) NSOperationQueue *queue;
+@property (readonly) NSString *sessionToken;
 
 
 // Initialization
diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.m b/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.m
index a65d243590e..38d4f114933 100644
--- a/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.m
+++ b/openbis-ipad/BisKit/Classes/CISDOBIpadServiceManager.m
@@ -104,6 +104,11 @@ static NSManagedObjectContext* GetMainThreadManagedObjectContext(NSURL* storeUrl
     return self;
 }
 
+- (NSString *)sessionToken
+{
+   return ((CISDOBLiveConnection *)(self.service.connection)).sessionToken;
+}
+
 - (void)syncEntities:(NSArray *)rawEntities pruning:(BOOL)prune notifying:(CISDOBIpadServiceManagerCall *)managerCall
 {
     void (^syncBlock)(void) = ^{
diff --git a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.h b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.h
index bcad911ec1c..c126236e268 100644
--- a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.h
+++ b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.h
@@ -32,7 +32,7 @@
 @property (weak, nonatomic) IBOutlet UILabel *summaryHeaderLabel;
 @property (weak, nonatomic) IBOutlet UILabel *summaryLabel;
 @property (weak, nonatomic) IBOutlet UILabel *identifierLabel;
-@property (weak, nonatomic) IBOutlet UIImageView *imageView;
+@property (weak, nonatomic) IBOutlet UIWebView *webView;
 
 // Actions
 - (void)selectionDidChange;     //!< Signals that the user has made a final selction
diff --git a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m
index 0fb7547cca2..76ba3b5239b 100644
--- a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m
+++ b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m
@@ -80,8 +80,14 @@
     self.summaryLabel.text = self.detailItem.summary;
     self.identifierLabel.text = self.detailItem.identifier;
 
-    if (self.imageView.image != self.detailItem.image) {
-        self.imageView.image = self.detailItem.image;
+    if (self.detailItem.imageUrlString) {
+        NSURL *url = [self.openBisModel urlFromUrlString: self.detailItem.imageUrlString];
+        NSURLRequest *request = [NSURLRequest requestWithURL: url];
+        [self.webView loadRequest: request];
+    } else {
+        NSURL *url = [NSURL URLWithString: @"about:blank"];
+        NSURLRequest *request = [NSURLRequest requestWithURL: url];
+        [self.webView loadRequest: request];
     }
     
     [self.propertiesTableView reloadData];
diff --git a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h
index d1f6f47894c..e7a4db47657 100644
--- a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h
+++ b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h
@@ -31,6 +31,7 @@
 
 @property (strong, nonatomic) CISDOBDetailViewController *detailViewController;
 @property (strong, nonatomic) CISDOBOpenBisModel *openBisModel;
+@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
 
 // Server Communication
 - (void)didConnectServiceManager:(CISDOBIpadServiceManager *)serviceManager;
diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h
index 60c2341293d..d2148e39c14 100644
--- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h
+++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h
@@ -60,6 +60,9 @@
 - (BOOL)insertNewObjectOrError:(NSError **)error; //!< Return YES if operation succeeded
 - (BOOL)deleteObjectAtIndexPath:(NSIndexPath *)indexPath error:(NSError **)error; //!< Return YES if operation succeeded
 
+// Utilities
+- (NSURL *)urlFromUrlString:(NSString *)urlString;
+
 // Server Communication
 - (void)syncRootEntities:(SuccessBlock)success;
 
diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m
index 0f12d0c09c6..14d66112652 100644
--- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m
+++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m
@@ -76,6 +76,24 @@
     return [self.fetchedResultsController objectAtIndexPath:indexPath];
 }
 
+#pragma mark - Utilities
+- (NSString *)sessionToken
+{
+    return self.serviceManager.sessionToken;
+}
+
+- (NSURL *)urlFromUrlString:(NSString *)urlString
+{
+    // if this is a datastore_server url, add the session token
+    NSRange dataStoreServerRange = [urlString rangeOfString: @"datastore_server"];
+    if (dataStoreServerRange.length == 0) return [NSURL URLWithString: urlString];
+    
+    NSMutableString *urlStringWithSession = [NSMutableString stringWithString: urlString];
+    [urlStringWithSession appendFormat: @"?sessionID=%@", [self sessionToken]];
+
+    return [NSURL URLWithString: urlStringWithSession];
+}
+
 #pragma mark - Selection
 - (CISDOBIpadEntity *)selectObjectAtIndexPath:(NSIndexPath *)indexPath
 {
@@ -140,18 +158,6 @@
     call.success = ^(id result) {
         // Update the UI
         localSuccess(_selectedObject);
-
-        // Load the image if necessary
-        if (_selectedObject.imageUrl && !_selectedObject.image) {
-            NSBlockOperation *blockOp = [NSBlockOperation blockOperationWithBlock:  ^{
-                NSURL *imageUrl = [NSURL URLWithString: _selectedObject.imageUrl];
-                NSData *imageData = [NSData dataWithContentsOfURL: imageUrl];
-                _selectedObject.image = [UIImage imageWithData: imageData];
-                // Update the UI again
-                localSuccess(_selectedObject);
-            }];
-            [blockOp start];
-        }
     };
     [call start];
 
diff --git a/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard b/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard
index 84b50785670..e46f75bc7f8 100644
--- a/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard
+++ b/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard
@@ -52,6 +52,7 @@
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="118" id="Txf-bY-brd"/>
+                                    <constraint firstAttribute="width" constant="415" id="mHb-8C-05c"/>
                                 </constraints>
                                 <fontDescription key="fontDescription" type="system" size="system"/>
                                 <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@@ -90,25 +91,26 @@
                                     <outlet property="delegate" destination="4" id="ZAW-uH-UCE"/>
                                 </connections>
                             </tableView>
-                            <imageView userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="NAn-y2-IQm">
+                            <webView contentMode="scaleToFill" scalesPageToFit="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rUU-Fj-t5t">
+                                <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                                 <constraints>
-                                    <constraint firstAttribute="width" constant="240" id="TCn-VB-07Q"/>
+                                    <constraint firstAttribute="width" constant="231" id="1jB-hU-Cjx"/>
                                 </constraints>
-                            </imageView>
+                                <dataDetectorType key="dataDetectorTypes"/>
+                            </webView>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                         <constraints>
                             <constraint firstItem="T4E-dH-b3j" firstAttribute="leading" secondItem="26" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="1JH-U6-rvC"/>
                             <constraint firstItem="bUx-j7-YCF" firstAttribute="top" secondItem="T4E-dH-b3j" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="34W-Bo-fwe"/>
                             <constraint firstItem="T4E-dH-b3j" firstAttribute="top" secondItem="gor-tF-mFh" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="8xN-U9-aRY"/>
-                            <constraint firstItem="NAn-y2-IQm" firstAttribute="top" secondItem="26" secondAttribute="top" constant="20" symbolic="YES" type="default" id="9gN-uv-Q6Q"/>
                             <constraint firstAttribute="bottom" secondItem="bUx-j7-YCF" secondAttribute="bottom" constant="20" symbolic="YES" type="default" id="BOD-5p-64L"/>
-                            <constraint firstItem="bUx-j7-YCF" firstAttribute="top" secondItem="NAn-y2-IQm" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="Ep0-Ma-f3g"/>
                             <constraint firstItem="27" firstAttribute="top" secondItem="26" secondAttribute="top" constant="20" symbolic="YES" type="user" id="FD4-HZ-RnC"/>
-                            <constraint firstItem="27" firstAttribute="trailing" secondItem="gor-tF-mFh" secondAttribute="trailing" type="default" id="HeN-P2-X4T"/>
-                            <constraint firstItem="NAn-y2-IQm" firstAttribute="leading" secondItem="T4E-dH-b3j" secondAttribute="trailing" constant="8" symbolic="YES" type="default" id="R01-gk-yuU"/>
+                            <constraint firstItem="bUx-j7-YCF" firstAttribute="top" secondItem="rUU-Fj-t5t" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="NfB-38-VMG"/>
+                            <constraint firstItem="rUU-Fj-t5t" firstAttribute="top" secondItem="26" secondAttribute="top" constant="20" symbolic="YES" type="default" id="QCg-PZ-dXE"/>
+                            <constraint firstAttribute="trailing" secondItem="rUU-Fj-t5t" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="Qpl-Gy-9XI"/>
                             <constraint firstItem="gor-tF-mFh" firstAttribute="top" secondItem="27" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="T1F-6Z-kbc"/>
-                            <constraint firstAttribute="trailing" secondItem="NAn-y2-IQm" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="ftL-M6-1yr"/>
+                            <constraint firstItem="gor-tF-mFh" firstAttribute="trailing" secondItem="27" secondAttribute="trailing" type="default" id="Tl9-Ul-Mrh"/>
                             <constraint firstAttribute="trailing" secondItem="bUx-j7-YCF" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="jU1-bA-JE1"/>
                             <constraint firstItem="27" firstAttribute="leading" secondItem="26" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="lGv-yZ-eAZ"/>
                             <constraint firstItem="bUx-j7-YCF" firstAttribute="leading" secondItem="26" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="qCU-93-jXk"/>
@@ -119,10 +121,10 @@
                     <navigationItem key="navigationItem" title="Detail" id="53"/>
                     <connections>
                         <outlet property="identifierLabel" destination="gor-tF-mFh" id="NCy-K7-tLT"/>
-                        <outlet property="imageView" destination="NAn-y2-IQm" id="4m7-UX-7kG"/>
                         <outlet property="propertiesTableView" destination="bUx-j7-YCF" id="QW1-J0-g9j"/>
                         <outlet property="summaryHeaderLabel" destination="27" id="f5M-Ao-eBL"/>
                         <outlet property="summaryLabel" destination="T4E-dH-b3j" id="qVC-t4-llZ"/>
+                        <outlet property="webView" destination="rUU-Fj-t5t" id="N50-LI-vy0"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="15" sceneMemberID="firstResponder"/>
@@ -215,14 +217,17 @@
             <source key="sourceIdentifier" type="project" relativePath="./Classes/CISDOBDetailViewController.h"/>
             <relationships>
                 <relationship kind="outlet" name="identifierLabel" candidateClass="UILabel"/>
-                <relationship kind="outlet" name="imageView" candidateClass="UIImageView"/>
                 <relationship kind="outlet" name="propertiesTableView" candidateClass="UITableView"/>
                 <relationship kind="outlet" name="summaryHeaderLabel" candidateClass="UILabel"/>
                 <relationship kind="outlet" name="summaryLabel" candidateClass="UILabel"/>
+                <relationship kind="outlet" name="webView" candidateClass="UIWebView"/>
             </relationships>
         </class>
         <class className="CISDOBMasterViewController" superclassName="UITableViewController">
             <source key="sourceIdentifier" type="project" relativePath="./Classes/CISDOBMasterViewController.h"/>
+            <relationships>
+                <relationship kind="outlet" name="searchBar" candidateClass="UISearchBar"/>
+            </relationships>
         </class>
         <class className="NSLayoutConstraint" superclassName="NSObject">
             <source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
-- 
GitLab