"Fossies" - the Fresh Open Source Software Archive

Member "opengroupware-5.5rc3/WebUI/Project/LSWProject/LSWProjectJobList.m" (5 Dec 2015, 11344 Bytes) of package /linux/privat/opengroupware-5.5rc3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "LSWProjectJobList.m" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.5rc2_vs_5.5rc3.

    1 /*
    2   Copyright (C) 2000-2005 SKYRIX Software AG
    3 
    4   This file is part of OpenGroupware.org.
    5 
    6   OGo is free software; you can redistribute it and/or modify it under
    7   the terms of the GNU Lesser General Public License as published by the
    8   Free Software Foundation; either version 2, or (at your option) any
    9   later version.
   10 
   11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
   12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   14   License for more details.
   15 
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with OGo; see the file COPYING.  If not, write to the
   18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   19   02111-1307, USA.
   20 */
   21 
   22 #include <OGoFoundation/LSWContentPage.h>
   23 
   24 @class NSString, NSArray;
   25 @class EOGlobalID;
   26 
   27 @interface LSWProjectJobList : LSWContentPage
   28 {
   29 @private
   30   EOGlobalID *projectId;
   31   id         project;
   32   id         jobs;
   33   NSString   *sortedKey;
   34 
   35   unsigned   startIndex;
   36   BOOL       isDescending;
   37   id         job;
   38   id         subJob;
   39   id         selectedAttribute;
   40   BOOL       showProjectReport;
   41   id         highestJob;
   42 }
   43 
   44 - (id)project;
   45 - (NSArray *)jobs;
   46 
   47 @end
   48 
   49 #include "common.h"
   50 
   51 static NSArray *_getSubJobExecutants(NSArray *_list) {
   52   NSMutableArray *array      = [NSMutableArray arrayWithCapacity:32];
   53   id             obj         = nil;
   54   Class          arrayClass  = [NSArray class];
   55   register IMP   objAtIdx;
   56   register IMP   addObj;  
   57   register int   i, cnt;
   58 
   59   objAtIdx = [_list methodForSelector:@selector(objectAtIndex:)];
   60   addObj   = [array methodForSelector:@selector(addObjectsFromArray:)];
   61                     
   62   for (i = 0, cnt = [_list count]; i < cnt; i++) {
   63     obj = [objAtIdx(_list, @selector(objectAtIndex:), i) valueForKey:@"jobs"];
   64     if ([obj isKindOfClass:arrayClass]) 
   65       addObj(array, @selector(addObjectsFromArray:), obj);
   66   }
   67   return array;                    
   68 }
   69 
   70 @implementation LSWProjectJobList
   71 
   72 - (id)init {
   73   if ((self = [super init])) {
   74     self->sortedKey = [@"jobStatus" retain];
   75   }
   76   return self;
   77 }
   78 
   79 - (void)dealloc {
   80   [self->projectId release];
   81   [self->project release];
   82   [self->jobs release];
   83   [self->sortedKey release];
   84   [self->job release];
   85   [self->subJob release];
   86   [self->selectedAttribute release];
   87   [self->highestJob release];
   88   [super dealloc];
   89 }
   90 
   91 /* activation */
   92 
   93 - (void)_fetchJobs {
   94   id toJob;
   95   
   96   NSAssert(([self project] != nil), @"No project set");
   97   
   98   [self runCommand:@"project::get-jobs",
   99         @"object",      [self project],
  100         @"relationKey", @"jobs", nil];
  101 
  102   toJob = [[self project] valueForKey:@"jobs"];
  103 
  104   toJob = [self runCommand:@"job::remove-waste-jobs", @"jobs", toJob, nil];
  105   
  106   [self runCommand:@"job::get-job-executants",
  107           @"objects", toJob,
  108           @"relationKey", @"executant",
  109           nil];
  110   [self runCommand:@"job::setcreator",
  111           @"objects",      toJob,
  112           @"relationKey", @"creator",
  113           nil];
  114   [self runCommand:@"job::get-job-executants",
  115           @"objects",
  116           _getSubJobExecutants(toJob),
  117           @"relationKey", @"executant",
  118           nil];
  119   ASSIGN(self->jobs, toJob);
  120 }
  121 
  122 - (void)syncAwake {
  123   [super syncAwake];
  124   [self _fetchJobs];
  125 }
  126 
  127 /* accessors */
  128 
  129 - (void)setProject:(id)_project {
  130   ASSIGN(self->project, _project);
  131 }
  132 - (id)project {
  133   if (self->project)
  134     return self->project;
  135   
  136   if (self->projectId) {
  137     self->project = [[self run:@"project::get",
  138                            @"gid", self->projectId,
  139                            nil] lastObject];
  140     
  141     self->project = [self->project retain];
  142   }
  143   return self->project;
  144 }
  145 
  146 - (void)setProjectId:(EOGlobalID *)_gid {
  147   ASSIGNCOPY(self->projectId, _gid);
  148 }
  149 - (id)projectId {
  150   return self->projectId;
  151 }
  152 
  153 - (void)setSortedKey:(NSString *)_sortedKey {
  154   ASSIGN(self->sortedKey,_sortedKey);
  155 }
  156 - (NSString *)sortedKey {
  157   return self->sortedKey;
  158 }
  159 
  160 - (NSArray *)jobs {
  161   if ([self->sortedKey isNotEmpty]) {
  162     EOSortOrdering *so;
  163     SEL            sel;
  164     NSArray        *sorted;
  165 
  166     sel = (self->isDescending) ? EOCompareDescending : EOCompareAscending;
  167     so = [EOSortOrdering sortOrderingWithKey:self->sortedKey selector:sel];
  168     sorted = [NSArray arrayWithObject:so];
  169     sorted = [self->jobs sortedArrayUsingKeyOrderArray:sorted];
  170     ASSIGN(self->jobs, sorted);
  171   }
  172   return self->jobs;
  173 }
  174 
  175 - (void)setSubJob:(id)_subJob {
  176   ASSIGN(self->subJob, _subJob);
  177 }
  178 - (id)subJob {
  179   return self->subJob;
  180 }
  181 
  182 - (void)setJob:(id)_job {
  183   ASSIGN(self->job, _job);
  184 }
  185 - (id)job {
  186   return self->job;
  187 }
  188 
  189 - (void)setSelectedAttribute:(id)_attr {
  190   ASSIGN(self->selectedAttribute, _attr);
  191 }
  192 - (id)selectedAttribute {
  193   return self->selectedAttribute;
  194 }
  195 
  196 - (void)setStart:(unsigned)_startIndex {
  197   self->startIndex = _startIndex;
  198 }
  199 - (unsigned)start {
  200   return self->startIndex;    
  201 }
  202 
  203 - (void)setIsDescending:(BOOL)_isDescending {
  204   self->isDescending = _isDescending;
  205 }
  206 - (BOOL)isDescending {
  207   return self->isDescending;    
  208 }
  209 
  210 - (BOOL)endDateOutOfTimeBool {
  211   NSCalendarDate *now;
  212   NSCalendarDate *eD;
  213 
  214   now = [NSCalendarDate date];
  215   eD  = [self->job valueForKey:@"endDate"];
  216   
  217   [now setTimeZone:[eD timeZone]];
  218   if ([[eD beginOfDay] compare:[now beginOfDay]] == NSOrderedAscending)
  219     return YES;
  220   return NO;
  221 }
  222 
  223 - (id)jobStatus {
  224   return [[self job] valueForKey:@"jobStatus"];
  225 }
  226 
  227 - (id)priority  {
  228   return [[self job] valueForKey:@"priority"];
  229 }
  230 
  231 - (NSString *)statusIcon {
  232   static NSDictionary *iconMap = nil;
  233 
  234   if (iconMap == nil) {
  235     iconMap = [[NSDictionary alloc] initWithObjectsAndKeys:
  236                                     @"led_red.gif",    @"00_created",
  237                                     @"led_yellow.gif", @"20_processing",
  238                                     @"led_green.gif",  @"25_done",
  239                                     @"led_red.gif",    @"02_rejected",
  240                                     @"led_dark.gif",   @"30_archived",
  241                                     nil];
  242   }
  243   return [iconMap valueForKey:[self jobStatus]];
  244 }
  245 
  246 - (id)enddateColor {
  247   return [self endDateOutOfTimeBool] ? @"#FF0000" : @"000000";
  248 }
  249 
  250 - (BOOL)creatorIsVisible {
  251   id am, gid;
  252 
  253   am  = [[[self session] commandContext] accessManager];
  254   gid = [[[self job] valueForKey:@"creator"] valueForKey:@"globalID"];
  255 
  256   return [am operation:@"r" allowedOnObjectID:gid];
  257 }
  258 
  259 - (BOOL)executantIsVisible {
  260   id  am, gid;
  261   
  262   am  = [[[self session] commandContext] accessManager];
  263   gid = nil;
  264   
  265   if ([[[self job] valueForKey:@"isTeamJob"] boolValue])
  266     return YES;
  267 
  268   gid = [[[self job] valueForKey:@"executant"] valueForKey:@"globalID"];
  269   return [am operation:@"r" allowedOnObjectID:gid];
  270 }
  271 
  272 - (void)setShowProjectReport:(BOOL)_showReport {
  273   self->showProjectReport = _showReport;
  274 }
  275 - (BOOL)showProjectReport {
  276   return self->showProjectReport;
  277 } 
  278 
  279 - (void)setHighestJob:(id)_job {
  280   ASSIGN(self->highestJob, _job);
  281 }
  282 - (id)highestJob {
  283   return self->highestJob;
  284 }
  285 
  286 /* access control */
  287 
  288 - (BOOL)isEditDisabled {
  289   BOOL isEnabled;
  290   id sn, accountId, obj;
  291 
  292   sn        = [self session];
  293   accountId = [[sn activeAccount] valueForKey:@"companyId"];
  294   obj       = [self project];
  295 
  296   isEnabled = (([accountId isEqual:[obj valueForKey:@"ownerId"]]) ||
  297                ([sn activeAccountIsRoot]));
  298 
  299   return !isEnabled;
  300 }
  301 
  302 /* actions */
  303 
  304 - (id)viewJob {
  305   return [self activateObject:self->job withVerb:@"view"];
  306 }
  307 
  308 - (id)viewSubJob {
  309   return [self activateObject:self->subJob withVerb:@"view"];
  310 }
  311 
  312 - (NSString *)jobImportCallBack {
  313   /* only set import callback when edit permission is set */
  314   return [self isEditDisabled] ? nil : (id)@"import";
  315 }
  316 
  317 - (id)newJob {
  318   id ct = nil;
  319   id sn = nil;
  320 
  321   sn = [self session];
  322   
  323   [sn removeTransferObject];
  324 
  325   ct = [sn instantiateComponentForCommand:@"new"
  326            type:[NGMimeType mimeType:@"eo/job"]];
  327 
  328   [ct takeValue:[self project] forKey:@"project"];
  329   [[sn navigation] enterPage:ct];
  330 
  331   return nil;
  332 }
  333 
  334 /* job report additions */
  335 
  336 - (NSNumber *)sumForAttribute:(NSString *)_attribute {
  337   NSEnumerator *jobEnum;
  338   id curJob, j;
  339   int sum = 0, high = 0;
  340 
  341   j = [self jobs];
  342 
  343   if ([j count] == 0)
  344     return nil;
  345   
  346   jobEnum = [j objectEnumerator];
  347   while ((curJob = [jobEnum nextObject])) {
  348     int cur;
  349     
  350     cur = [[curJob valueForKey:_attribute] intValue];
  351 
  352     if (cur > high) {
  353       [self setHighestJob:curJob];
  354       high = cur;
  355     }
  356     sum += cur;
  357   }
  358   return [NSNumber numberWithInt:sum];
  359 }
  360 
  361 - (NSString *)stringForAttribute:(NSString *)_attr
  362   withUnitLabel:(NSString *)_label
  363 {
  364   id l;
  365   NSNumber *s;
  366   double c, percent;
  367 
  368   l = [self labels];
  369 
  370   if ((s = [self sumForAttribute:_attr]) == nil) {
  371     return [l valueForKey:@"noJobAssociated"];
  372   }
  373   else if ([s intValue] == 0) {
  374     return [l valueForKey:[NSString stringWithFormat:@"no%@Data",
  375                                     _attr]];
  376   }
  377   else {
  378     c = [[[self highestJob] valueForKey:_attr] doubleValue];
  379     percent = (c / [s doubleValue]) * 100;
  380   }
  381   
  382   return [NSString stringWithFormat:@"%@ %@ %@ %"PRIuPTR" %@, %.0f %@ (%.0f %%) %@ %@",
  383                    s, [l valueForKey:_label],
  384                    [l valueForKey:@"in"], [[self jobs] count],
  385                    [l valueForKey:@"jobsLabel"], c,
  386                    [l valueForKey:_label], percent,
  387                    [l valueForKey:@"in"], [l valueForKey:@"jobLabel"]];
  388 }
  389 
  390 - (NSString *)actualWorkString {
  391   return [self stringForAttribute:@"actualWork"
  392                withUnitLabel:@"minutesLabel"];
  393 }
  394 
  395 - (NSString *)totalWorkString {
  396   return [self stringForAttribute:@"totalWork"
  397                withUnitLabel:@"minutesLabel"];
  398 }
  399 
  400 - (NSString *)kilometersString {
  401   return [self stringForAttribute:@"kilometers"
  402                withUnitLabel:@"kilometersLabel"];
  403 }
  404 
  405 - (NSString *)percentCompleteString {
  406   NSString *result;
  407   NSNumber *s;
  408   id l;
  409   double c, i;
  410 
  411   l = [self labels];
  412 
  413   if ((s = [self sumForAttribute:@"percentComplete"]) == nil) {
  414     return [l valueForKey:@"noJobAssociated"];
  415   }
  416   else if ([s intValue] == 0) {
  417     return [l valueForKey:@"nopercentData"];
  418   }
  419   else {
  420     c = [[[self highestJob] valueForKey:@"percentComplete"] doubleValue];
  421     i = [s doubleValue] / [[self jobs] count];
  422   }
  423   
  424   result = [NSString stringWithFormat:@"%.0f %@ %@ %"PRIuPTR" %@",
  425                      i, [l valueForKey:@"percent"],
  426                      [l valueForKey:@"in"], [[self jobs] count],
  427                      [l valueForKey:@"jobsLabel"]];
  428 
  429 
  430   if (c < 100)
  431     return [result stringByAppendingFormat:@", %.0f %@ %@ %@",
  432                    c,
  433                    [l valueForKey:@"percent"],
  434                    [l valueForKey:@"in"], [l valueForKey:@"jobLabel"]];
  435   else
  436     return [result stringByAppendingFormat:@", %@ %@ %@",
  437                    [l valueForKey:@"25_done"],
  438                    [l valueForKey:@"in"], [l valueForKey:@"jobLabel"]];
  439 }
  440 
  441 - (NSString *)jobHref {
  442   NSDictionary *dict;
  443 
  444   dict = [NSDictionary dictionaryWithObjectsAndKeys:
  445                        [[self session] sessionID], @"wosid", 
  446                        [[self context] contextID], @"cid",
  447                        [self->highestJob valueForKey:@"jobId"], @"jobId",
  448                        nil];
  449   return [[self context] directActionURLForActionNamed:@"LSWViewAction/viewJob"
  450                          queryDictionary:dict];
  451 }
  452 
  453 @end /* LSWProjectJobList */