summaryrefslogtreecommitdiffstats
path: root/src/modules/line_break.rs
AgeCommit message (Collapse)Author
2021-02-11refactor(clippy): fix new lints (#2297)David Knaack
2020-09-21feat: Add timings subcommand (#1629)Jan Katins
* feat: Add computational duration to all computed modules This also means that in case we do some computations and these end up empty, we submit an empty module * feat: Add timings subcommand This outputs the timings of all computed modules, sorted by the duration it took to compute the module. Useful for debugging why the prompt takes so long. * feat: Add timings to explain output * fix: Ensure that even empty custom modules get timings * format main.rs * feat: Only show interesting timings * fix(tests): Change tests to look for empty string instead of None * Use proper wording in timings help * Revert "fix(tests): Change tests to look for empty string instead of None" This reverts commit aca5bd1b03c48e1dee1b7ca91d66e2bda2d5a97c. * fix(tests): Returning None in case the module produced an empty string * fix: Ensure that linebreaks (and space) make a module not-empty * Make cargo clippy happy * Make Module.duration a proper Duration * Only return a module if we would report it * Change to cleaner way to return None for empty modules * Avoid unnecessary module creation * Simplify a string comparison * Add timings to trace Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com> Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
2020-08-17Revert "fix: restore add_newline configuration (#1592)" (#1596)Matan Kushner
2020-08-16fix: restore add_newline configuration (#1592)Matan Kushner
2020-08-16chore: remove unused name from Segment and remove some of the misleading ↵Tilmann Meyer
underscores (#1584) * chore: Remove unused name from Segment and remove some of the misleading underscores * chore: Access members of `Segment` directly
2020-07-07feat: refactor modules to use format strings (#1374)Zhenhui Xie
2019-10-10refactor: Rewrite hostname, jobs and line_break module to use mo… (#462)Zhenhui Xie
2019-10-04refactor: Go from Rust workspaces to a package with nested packages (#480)Matan Kushner
2019-09-30refactor: Refactoring config (#383)Zhenhui Xie
This PR refactors config and puts configuration files for all modules in `configs/`.
2019-09-09fix: Lazy load git repo and only run module if not disabled (#306)Neil Kistner
A couple of optimizations are done in this PR. One, we now will check config ahead of time to see if a module is disabled before running any module code. Also, we won't try to discover a git repository unless the module requests access to it.
2019-07-19docs: Add vuepress with initial docs (#99)Tiffany Le-Nguyen
Co-authored-by: Tiffany Le-Nguyen <tlenguyen@expedia.com> Co-authored-by: Matan Kushner <hello@matchai.me>
2019-07-02feat: Add a `disabled` configuration option for modules (#86)Matan Kushner
• Add support for the disabled configuration option This will allow you to selectively disable modules that you don't want or need. 😄 • Overwrite starship configuration file path with STARSHIP_CONFIG environment variable • Write tests for the two configuration options that are available
2019-06-10Add support for prompt configuration (#62)Matan Kushner
- Create `Config` struct that is added to `Context` when initialized - Read `~/.confg/starship.toml` during initialization (can be updated later to also look at `$XDG_CONFIG_HOME`) - `Context` now has a method for creating modules. This allows us to provide modules with a reference to the configuration specific to that module
2019-05-01Refactor segments into modules (#40)Matan Kushner
2019-04-19Use "context" to contain run details (#14)Matan Kushner
* Create "context" to contain run details * Use context in tests and benchmarks
2019-04-15Add integration tests (#6)Matan Kushner
### Changed - Added current_dir param to segments to make them more testable - Moved all existing integration tests to a `tests/` dir ### Added - A whole bunch of new integration tests
2019-04-12Make segments optionalsMatan Kushner
2019-04-12Use copy to return segmentMatan Kushner
2019-04-04Rename segementsMatan Kushner
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
/**
 * Nextcloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Bernhard Posselt 2014
 */
app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) {
    'use strict';

    var FeedResource = function ($http, BASE_URL, $q) {
        Resource.call(this, $http, BASE_URL, 'url');
        this.ids = {};
        this.locations = {};
        this.unreadCount = 0;
        this.folderUnreadCount = {};
        this.folderIds = {};
        this.$q = $q;
    };

    FeedResource.prototype = Object.create(Resource.prototype);

    FeedResource.prototype.receive = function (data) {
        Resource.prototype.receive.call(this, data);
        this.updateUnreadCache();
        this.updateFolderCache();
    };

    FeedResource.prototype.clear = function () {
        Resource.prototype.clear.call(this);
        this.unreadCount = 0;
        this.folderUnreadCount = {};
        this.folderIds = {};
        this.ids = {};
        this.locations = {};
    };

    FeedResource.prototype.updateUnreadCache = function () {
        this.unreadCount = 0;
        this.folderUnreadCount = {};

        var self = this;
        this.values.forEach(function (feed) {
            if (feed.unreadCount) {
                self.unreadCount += feed.unreadCount;
            }
            if (feed.folderId !== undefined) {
                self.folderUnreadCount[feed.folderId] =
                    self.folderUnreadCount[feed.folderId] || 0;
                self.folderUnreadCount[feed.folderId] += feed.unreadCount;
            }
        });
    };


    FeedResource.prototype.updateFolderCache = function () {
        this.folderIds = {};

        var self = this;
        this.values.forEach(function (feed) {
            self.folderIds[feed.folderId] =
                self.folderIds[feed.folderId] || [];
            self.folderIds[feed.folderId].push(feed);
        });
    };


    FeedResource.prototype.add = function (value) {
        Resource.prototype.add.call(this, value);
        if (value.id !== undefined) {
            this.ids[value.id] = this.hashMap[value.url];
        }
        if (value.location !== undefined) {
            this.locations[value.location] = this.hashMap[value.url];
        }
    };


    FeedResource.prototype.markRead = function () {
        this.values.forEach(function (feed) {
            feed.unreadCount = 0;
        });

        this.updateUnreadCache();
    };


    FeedResource.prototype.markFeedRead = function (feedId) {
        this.ids[feedId].unreadCount = 0;
        this.updateUnreadCache();
    };


    FeedResource.prototype.markFolderRead = function (folderId) {
        this.values.forEach(function (feed) {
            if (feed.folderId === folderId) {
                feed.unreadCount = 0;
            }
        });

        this.updateUnreadCache();
    };


    FeedResource.prototype.markItemOfFeedRead = function (feedId) {
        this.ids[feedId].unreadCount -= 1;
        this.updateUnreadCache();
    };


    FeedResource.prototype.markItemsOfFeedsRead = function (feedIds) {
        var self = this;
        feedIds.forEach(function (feedId) {
            self.ids[feedId].unreadCount -= 1;
        });

        this.updateUnreadCache();
    };


    FeedResource.prototype.markItemOfFeedUnread = function (feedId) {
        this.ids[feedId].unreadCount += 1;
        this.updateUnreadCache();
    };


    FeedResource.prototype.getUnreadCount = function () {
        return this.unreadCount;
    };


    FeedResource.prototype.getFolderUnreadCount = function (folderId) {
        return this.folderUnreadCount[folderId];
    };


    FeedResource.prototype.getByFolderId = function (folderId) {
        return this.folderIds[folderId] || [];
    };


    FeedResource.prototype.getById = function (feedId) {
        return this.ids[feedId];
    };


    FeedResource.prototype.getByLocation = function (location) {
        return this.locations[location];
    };


    FeedResource.prototype.move = function (feedId, folderId) {
        var feed = this.getById(feedId);
        feed.folderId = folderId;

        this.updateFolderCache();
        this.updateUnreadCache();

        return this.patch(feedId, {folderId: folderId});

    };


    FeedResource.prototype.create = function (url, folderId, title, user,
                                              password) {
        url = url.trim();
        if (!url.startsWith('http')) {
            url = 'https://' + url;
        }

        if (title !== undefined) {
            title = title.trim();
        }

        var feed = {
            url: url,
            folderId: folderId || 0,
            title: title || url,
            unreadCount: 0
        };

        this.add(feed);
        this.updateFolderCache();

        var deferred = this.$q.defer();

        this.http({
            method: 'POST',
            url: this.BASE_URL + '/feeds',
            data: {
                url: url,
                parentFolderId: folderId || 0,
                title: title,
                user: user || null,
                password: password || null
            }
        }).success(function (data) {
            deferred.resolve(data);
        }).error(function (data) {
            feed.faviconLink = '';
            feed.error = data.message;
            deferred.reject();
        });

        return deferred.promise;
    };


    FeedResource.prototype.reversiblyDelete = function (id, updateCache,
                                                        isFolder) {
        var feed = this.getById(id);

        // if a folder is deleted it does not have to trigger the delete
        // attribute for the feed because the feed is not deleted, its just not
        // displayed. Otherwise this causes the feed to also be deleted again
        // because the folder destroys the feed's scope
        if (feed && isFolder !== true) {
            feed.deleted = true;
        }

        if (updateCache !== false) {
            this.updateUnreadCache();
        }

        return this.http.delete(this.BASE_URL + '/feeds/' + id