Exemplo n.º 1
0
        public async Task <IActionResult> PushStrings()
        {
            var stringsToPush = await _soStringService.GetStringsAsync(s => s.HasTranslation);

            if (stringsToPush.Length > 0)
            {
                var sendNotifications = (await _soStringService.GetStringsAsync(s => s.NeedsPush)).Length > 0;
                await _transifexService.PushStringsToTransifexAsync(stringsToPush);

                if (sendNotifications)
                {
                    await _userService.SendBatchNotifications(NotificationType.StringsPushedToTransifex, false, null);
                }
            }

            return(new EmptyResult());
        }
Exemplo n.º 2
0
 public async Task <IActionResult> GetStringStats()
 {
     return(Json(new
     {
         TotalStrings = (await _soStringService.GetStringsAsync(s => !s.IsIgnored)).Length,
         WithoutTranslation = (await _soStringService.GetStringsAsync(s => !s.HasTranslation && !s.IsIgnored)).Length,
         WithPendingSuggestions = (await _soStringService.GetStringsAsync(s => s.HasSuggestions && !s.IsIgnored)).Length,
         WaitingApproval = (await _soStringService.GetStringsAsync(s => s.HasSuggestionsWaitingApproval && !s.IsIgnored)).Length,
         WaitingReview = (await _soStringService.GetStringsAsync(s => s.HasApprovedSuggestionsWaitingReview && !s.IsIgnored)).Length,
         UrgentStrings = (await _soStringService.GetStringsAsync(s => s.IsUrgent && !s.IsIgnored)).Length,
     }));
 }
Exemplo n.º 3
0
        public async Task <IActionResult> PushStrings()
        {
            var stringsToPush = await _soStringService.GetStringsAsync(s => s.HasTranslation);

            if (stringsToPush.Length > 0)
            {
                await _transifexService.PushStringsToTransifexAsync(stringsToPush);
            }

            return(new EmptyResult());
        }
        public async Task <IActionResult> PushStrings()
        {
            var stringsToPush = await _soStringService.GetStringsAsync(s => s.HasTranslation, includeEverything : true);

            if (stringsToPush.Length > 0)
            {
                var sendNotifications = (await _soStringService.CountStringsAsync(s => s.NeedsPush)) > 0;
                await _transifexService.PushStringsToTransifexAsync(stringsToPush);

                if (sendNotifications)
                {
                    await _userService.SendBatchNotifications(NotificationType.StringsPushedToTransifex, null);
                }
            }

            return(NoContent());
        }
        public async Task <ImmutableArray <SOString> > Query(QueryViewModel model)
        {
            Func <SOString, bool> predicate = null;

            void ComposePredicate(Func <SOString, bool> newPredicate)
            {
                if (predicate == null)
                {
                    predicate = newPredicate;
                    return;
                }

                var oldPredicate = predicate;

                predicate = s => oldPredicate(s) && newPredicate(s);
            }

            if (model.TranslationStatus != TranslationStatus.AnyStatus)
            {
                ComposePredicate(s => s.HasTranslation == (model.TranslationStatus == TranslationStatus.WithTranslation));
            }

            if (model.PushStatus != PushStatus.AnyStatus)
            {
                ComposePredicate(s => s.NeedsPush == (model.PushStatus == PushStatus.NeedsPush));
            }

            if (model.UrgencyStatus != UrgencyStatus.AnyStatus)
            {
                ComposePredicate(s => s.IsUrgent == (model.UrgencyStatus == UrgencyStatus.IsUrgent));
            }

            if (model.IgnoredStatus != IgnoredStatus.IncludeIgnored)
            {
                ComposePredicate(s => s.IsIgnored == (model.IgnoredStatus == IgnoredStatus.OnlyIgnored));
            }

            if (model.SuggestionsStatus != SuggestionApprovalStatus.AnyStatus)
            {
                switch (model.SuggestionsStatus)
                {
                case SuggestionApprovalStatus.DoesNotHaveSuggestions:
                    ComposePredicate(s => !s.HasSuggestions);
                    break;

                case SuggestionApprovalStatus.HasSuggestionsNeedingReview:
                    ComposePredicate(s =>
                                     s.Suggestions != null &&
                                     s.Suggestions.Any(sug => sug.State == StringSuggestionState.Created || sug.State == StringSuggestionState.ApprovedByTrustedUser));
                    break;

                case SuggestionApprovalStatus.HasSuggestionsNeedingApproval:
                    ComposePredicate(s => s.HasSuggestionsWaitingApproval);
                    break;

                case SuggestionApprovalStatus.HasSuggestionsNeedingReviewApprovedByTrustedUser:
                    ComposePredicate(s => s.HasApprovedSuggestionsWaitingReview);
                    break;
                }
            }

            if (model.Key.HasValue())
            {
                ComposePredicate(s => s.Key.StartsWith(model.Key, true, CultureInfo.InvariantCulture));
            }

            if (model.SourceRegex.HasValue())
            {
                Regex regex;
                try
                {
                    regex = new Regex(model.SourceRegex, RegexOptions.Compiled);
                }
                catch (ArgumentException ex)
                {
                    throw new InvalidOperationException("Invalid source regex", ex);
                }

                ComposePredicate(s => regex.IsMatch(s.OriginalString));
            }

            if (model.TranslationRegex.HasValue())
            {
                Regex regex;
                try
                {
                    regex = new Regex(model.TranslationRegex, RegexOptions.Compiled);
                }
                catch (ArgumentException ex)
                {
                    throw new InvalidOperationException("Invalid translation regex", ex);
                }

                ComposePredicate(s => s.HasTranslation && regex.IsMatch(s.Translation));
            }

            return(await _soStringService.GetStringsAsync(predicate));
        }
Exemplo n.º 6
0
 public async Task <IActionResult> GetStringsByKey(string key)
 {
     return(Json(await _soStringService.GetStringsAsync(s => s.FamilyKey == key)));
 }